Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📚 Documentation: Realtime/Subscribe docs confusing #7050

Closed
2 tasks done
R0N1n-dev opened this issue Oct 31, 2023 · 2 comments
Closed
2 tasks done

📚 Documentation: Realtime/Subscribe docs confusing #7050

R0N1n-dev opened this issue Oct 31, 2023 · 2 comments

Comments

@R0N1n-dev
Copy link

💭 Description

Not sure about the realtime/subscription docs.
Subscribe works as described here

import { Client } from "appwrite";

const client = new Client()
    .setEndpoint('https://cloud.appwrite.io/v1')
    .setProject('[PROJECT_ID]');

client.subscribe('account', response => {
    // Callback will be executed on all account events.
    console.log(response);
});

Then docs talk about unsubscribe so as not to lead to race conditions

import { Client } from "appwrite";

const client = new Client()
    .setEndpoint('https://cloud.appwrite.io/v1')
    .setProject('[PROJECT_ID]');

const unsubscribe = client.subscribe('files', response => {
    // Callback will be executed on changes for all files.
    console.log(response);
});

// Closes the subscription.
unsubscribe();

If i use subscribe as the first one, it works, but it leaves it subscribed if i am not mistaken, hence the need for unsubscribe, but if i use the unsubscribe , i never get my callback.
How do i use subscribe and unsubscribe as well properly coz am confused according to the docs and the results in my app?????

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

@Utkarshn10
Copy link

Hey @R0N1n-dev the docs suggest to use subscribe if you are not duplicating your subscriptions. So I think you can use subscribe as per your usecase.

This is what docs suggests:
If you no longer want to receive updates from a subscription, you can unsubscribe so that your callbacks are no longer called. Leaving old subscriptions alive and resubscribing can result in duplicate subscriptions and cause race conditions.

@R0N1n-dev
Copy link
Author

Ok.Thanx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants