socket.io-client-csharp
socket.io-client-csharp copied to clipboard
Isolating ListenAsync in separate long-time task?
@doghappy
Would it be useful to isolate event reading task in separate long-time task?
I mean update code in method ConnectAsync(Uri uri) from:
_ = ListenAsync(_listenToken.Token);
to
_ = Task.Factory.StartNew( async () => await ListenAsync(_listenToken.Token).ConfigureAwait(false), TaskCreationOptions.LongRunning);
On the surface, they are the same. But I think it would be better to specify LongRunning.
https://stackoverflow.com/questions/25833054/what-does-long-running-tasks-mean
https://stackoverflow.com/questions/37607911/when-to-use-taskcreationoptions-longrunning
I think it's up to you.
From one side specifying of LongRunning is good idea but from other side the current code guaranties that listening task has been started when ConnectAsync() task ends execution and after my suggested changes ListenAsync could be started after ConnectAsync() task finishes execution (because Task.Factory.StartNew() can postpone task starting for some time).
So i don't know what is better:
- isolate
ListenAsyncin separate long-time task - or to have a guaranty that listening task has been started when
ConnectAsync()task finishes execution.