conductor-sdk / conductor-csharp

The conductor-csharp repository provides the client SDKs to build task workers in C#
Apache License 2.0
41 stars 16 forks source link

Async / Non blocking support #86

Closed ZergRushJoe closed 8 months ago

ZergRushJoe commented 1 year ago

I would like some interfaces to support tasks/async methods. Right now the main thread is blocked by any network call. This is a problem for using the api client. Workers can also be made async as well for pull loop would allow a cancelation token to be used so the worker can exit gracefully.

The Microsoft docs they use the async methods to avoid threading issues. https://learn.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-7.0&tabs=visual-studio

mmccord-processunity commented 9 months ago

@ZergRushJoe -- I had the same thought. It appears here that it was at one point async and then changed to synchronous. I assume there was some advantage to doing this, but I'm not seeing it. I asked @gardusig (the author of the commit) for comment. Additionally the documentation still indicates async here even though per @gardusig's change, it is now synchronous.

@LPFOXX you may also be interested in this based on your like above.

gardusig commented 9 months ago

Sorry, I'm not part of the company that maintains this repo anymore.

By the time I was mainly focused at managing workers to process tasks in parallel. Like super focused at using a single worker with batch poll, not that many IO operations. Maybe a code review could have helped to discuss that :)

gardusig commented 9 months ago

Quick explanation about overall architecture.

It was the first time I coded in C#, so I'm not that familiar with its multithreading handling. If the async issue is blocking multiple I/O operations at the same time. I think the code change to make that improvement might be quite short.

gardusig commented 9 months ago

Maybe it's as simple as adding an async before each method declaration and then making the right call at their infinite loop.

private async void Work4Ever()

Then play around with their main startup method

mmccord-processunity commented 9 months ago

Gotcha. Thanks for the info and the prompt reply!

ZergRushJoe commented 9 months ago

Yes can also use task.waitall as a way to run all the batched task at the same time but still wait for all to finsh before getting the next batch.