question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to know if an observable is successfully subscribed to a topic?

See original GitHub issue

Which 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:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
stocaarocommented, Aug 4, 2022

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.

0reactions
ume-danielcommented, Feb 8, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found