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.

Halt execution until server/client is ready after calling start

See original GitHub issue

Is there a way to block execution until the server is actually ready? Atm I’m doing a while loop that checks the IsListening variable which seems wasteful. Same with the client, except checking if the client IsConnected.

I would love to be able to do something like:

await WebsocketServer.Start() await WebsocketClient.Start()

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:24 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
jchristncommented, Feb 16, 2021

This should do it. I’m going to do some more research into returning the actual Task without blocking should it be awaited.

NuGet: https://www.nuget.org/packages/WatsonWebsocket/2.2.1.3 Commit: https://github.com/jchristn/WatsonWebsocket/commit/f5756d88e796da9b5c87b3240d3b4b71e7c13493

Please close if this works for you, or let me know if any issues remain!

Ex:

await _Server.StartAsync();
Console.WriteLine("Server is listening: " + _Server.IsListening);

image

1reaction
jchristncommented, Feb 13, 2021

We could add a StartAsync method to both, would that work? In the server it would return the AcceptConnections task, and in the client, it would return the ConnectAsync task; both could be awaited.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there any way to wait for AJAX response and halt ...
Here is some code I'd like to execute. I'd like to wait for AJAX response so I can return something from the server....
Read more >
Understanding and Handling Connection Lifetime Events ...
When a connection is inactive, periodically the server sends a keepalive packet to the client. As of the date this article is being...
Read more >
Let It Crash: Best Practices for Handling Node.js Errors on ...
Let's say we have a server running. It's receiving requests and establishing connections with clients. But what happens if the process crashes?
Read more >
Understanding Control Flow with Async and Await in C# | ...
GetResult() on the task, which is a blocking call. Again, this is synchronous; no execution will take place on the current thread until...
Read more >
Understanding the Event Loop, Callbacks, Promises, and ...
The task is to get the third function to always delay execution until after the asynchronous action in the second function has completed....
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