Answer the question
In order to leave comments, you need to log in
How to implement waiting for a method to execute without using a while loop?
Hello!
I have two separate services that are somehow interconnected. To one I send requests via HTTP, and from the other I expect a response via web sockets.
It works like this:
static async void Run()
{
await SendMessageToServer(); // отправить запрос по HTTP
WaitResponseFromWebSocket(); // ожидать ответа по веб сокету
}
Answer the question
In order to leave comments, you need to log in
If I understand correctly, the websocket message handler is running somewhere else. You can create a common TaskCompletionSource and call in the Run method await tcs.Task;
, and when a message arrives on the socket, call tcs.SetResult();
.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question