dimaaan / WebSocketTextClient

Wrapper around System.Net.WebSockets.ClientWebSocket that provides event based interface to exchange text messages over Web Sockets. Support cancellation
MIT License
1 stars 1 forks source link

Manage connection #2

Open dimaaan opened 7 years ago

dimaaan commented 7 years ago

from @Ruhrpottpatriot: I find it a bit counter intuitive, how you handled the keep alive process. If I understood it correctly, you call OpenAnsyc() and that Task only completes when the connection is closed.

Maybe change the code, so that every public async method accepts a CancellationToken and the receive Task is decoupled from ConnectAsync().

TaskCompletionSource could be an option. I'll look into it.

Ruhrpottpatriot commented 7 years ago

Additional information regarding a CancellationToken:

In TAP, cancellation is optional for both asynchronous method implementers and asynchronous method consumers. If an operation allows cancellation, it exposes an overload of the asynchronous method that accepts a cancellation token (CancellationToken instance). By convention, the parameter is named cancellationToken.

From: https://docs.microsoft.com/en-us/dotnet/standard/asynchronous-programming-patterns/task-based-asynchronous-pattern-tap

Ruhrpottpatriot commented 7 years ago

I also would suggest, that we add a new boolean property indicating whether the connection is open or not.