How to know if an observable is successfully subscribed to a topic?
See original GitHub issueWhich Category is your question related to? AWS Amplify - API Subscription Observable
What AWS Services are you utilizing? AWS Amplify, AppSync
Provide additional details e.g. code snippets I wanted to know when an observable is successfully subscribed to a specific topic. This is for the app to start triggering some actions.
Here’s what I tried thinking that complete
is the callback where the observer is “now connected” or subscribed.
subscription.subscribe({
next: (data) => {},
error: (error) => {},
complete: () => {
console.log('subscribed');
/* emit(subscribed()); */
},
});
Unfortunately, doesn’t print out 'subscribed'
.
Any thoughts?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Angular2. How can I check if an observable is completed?
You can do this by using onCompleted callback in subscription . For example, let's say you show loading bar when user press report...
Read more >An intro to Observables and how they are different from ...
The answer is Promises, Observables, callbacks and many more. We know that these asynchronous operations return responses, either some data ...
Read more >Best Practices for Managing RxJS Subscriptions - This Dot Labs
Essentially, subscription management revolves around knowing when to complete or unsubscribe from an Observable, to prevent incorrect code from ...
Read more >How to build Angular App with Observable Data Services
We subscribe to that same observable, and on success we calculate the new list of todos by adding the new todo to the...
Read more >A real world example of an Angular observable - Arroyo Labs
Subject is just an extension of Observable's interface; Its traits remain the same as that of Observables (meaning you can still use next(),...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
On Monday a change was released that adds AppSync subscription connection states to Hub. With this change, it is now possible to monitor as your subscription causes the connection to transition from Disconnected -> Connecting -> Connected so that your application can know when everything is up and working.
The documentation change to cover this behavior is currently in review.
This should cover the use-case described here, I’m going to resolve the issue, but would be happy to review further if there is any aspect of this problem not covered by the Hub events.
we run a “ping” test when we first create the subscription. we create the subscription and on a 1 second interval, send a message to that subscription with a unique id so that only we are listening to it. once we can “hear” our subscription, we disable the interval and proceed to initialize the correct subscription or do any other initialization.
NOTE: do not delete your “ping” subscription or at least wait until you subscribe to other subs as deleting the first subscription with no other’s initialized will result in the websocket closing down.