DEV Community

loading...

Discussion on: Wait for the WebSocket connection to be open, before sending a message

Collapse
ndrbrt profile image
Andrea Bertoloni Author • Edited

Well, my point is: since the open state depends on a network request that takes a certain amount of time to be completed and could eventually fail, I want my code to check the status only at given intervals; furthermore, since the request could fail, I don't to want to end up stuck in that loop forever, but eventually break it after n checks.

You could use async/await, but sometimes I just feel more comfortable using a Promise instead (after all an async function is just a sort of a shortcut that returns a Promise)