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.

Confirmation of a socket connection

See original GitHub issue

Picking up from @ToryByte’s tweet: https://twitter.com/ToryByte/status/1267225319947280385

Is there a way to wait for a subscription to connect? I cant find a way to wait for a subscription to be ready before I start running other statements. It would be nice if subscribe() returned a promise.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
VictorioBerracommented, Jun 1, 2020

This does help, this means that I can poll those until they return true.

Consider a use case for say, an ExpressJS app. You would want to launch your Express app but not start accepting requests until all your sockets were connected and ready.

1reaction
w3b6x9commented, Sep 26, 2022

This can be accomplished now depending on which version of realtime-js you’re using.

If you’re using realtime-js master/v1 then you can do:

 const mySubscription = supabase
  .from('*')
  .on('*', payload => {
    console.log('Change received!', payload)
  })
  .subscribe()
  .receive('ok', () => console.log('Subscribed successfully so do something'))

If you’re using realtime-js rc/v2 then you can do:

 const myChannel = supabase
  .channel('any')
  .on('postgres_changes', { event: '*', schema: 'public' }, payload => {
    console.log('Change received!', payload)
  })
  .subscribe(status => {
    if (status === 'SUBSCRIBED') {
       console.log('Subscribed successfully so do something')
    }
  })
Read more comments on GitHub >

github_iconTop Results From Across the Web

Check if socket is connected or not [duplicate] - Stack Overflow
Don't check first and then send. It's wasted effort and won't work anyway -- the status can change between when you check and...
Read more >
Sockets Tutorial
Sockets Tutorial. This is a simple tutorial on using sockets for interprocess communication. The client server model. by Robert Ingalls.
Read more >
Sample Code Illustrating a Secure Socket Connection ...
These samples illustrate how to set up a secure socket connection between a client and a server.
Read more >
Understanding Sockets - DigitalOcean
Stream sockets are connection oriented, which means that packets sent to and received from a network socket are delivered by the host ......
Read more >
Socket processing for transactions - IBM
The client application receives the output, sends an ACK, and must issue a READ to receive the next output or the timeout notification....
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