socket.io-client-csharp icon indicating copy to clipboard operation
socket.io-client-csharp copied to clipboard

Isolating ListenAsync in separate long-time task?

Open 23W opened this issue 4 years ago • 2 comments

@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);

23W avatar Aug 06 '21 08:08 23W

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

doghappy avatar Aug 27 '21 02:08 doghappy

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 ListenAsync in separate long-time task
  • or to have a guaranty that listening task has been started when ConnectAsync() task finishes execution.

23W avatar Aug 27 '21 08:08 23W