I am struggling with the observer pattern with NuGet package websocket-client (https://github.com/Marfusios/websocket-client)
The connection to the WebSocket server is stable and running.
Every request has a request ID inside the payload. The client sends it to the server and the server responds with the ID and the real data.
On the client side I need to assign every response to the corresponding request.
I thought I can do it like so:
public Task<Data> GetDataAsync()
{
var webSocket = new WebsocketClient(Uri);
await webSocket.Start();
var requestId = Guid.NewGuid();
var tcs = new TaskCompletionSource<Data>();
var disposable = webSocket
.MessageReceived
.Where(message => message.Text.Contains(requestId))
.Subscribe(message=>
{
var data = ParseData(message.Text);
tcs.SetResult(data);
});
return tcs.Task;
}
But it actually never jumps into the subscribe method. Am I using it wrong?