Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async handlers #21

Closed
valdisiljuconoks opened this issue Oct 29, 2020 · 2 comments
Closed

Async handlers #21

valdisiljuconoks opened this issue Oct 29, 2020 · 2 comments
Assignees
Labels

Comments

@valdisiljuconoks
Copy link

Hi,

Thanks for the library, it's great addition to our system. However, I was wondering - what do you think of adding support for async handlers?

We have subscription handler where we need to call async methods. Could wrap of course in some GetAwaiter magic, but was wondering about "native" support from the hub side.

Any pointers whether this could be complex to add? Probably can contrib if you give some heads up ideas.

Thanks!

@NimaAra
Copy link
Owner

NimaAra commented Oct 29, 2020

Hi,

I had intentionally not included support for asynchronous handlers as Tasks. This is by design as hub's only responsibility is to raise the events as they come in (fire and forget) it should not await for subscribers to finish processing them.

I would suggest (depending on your use-case) to consume your events by adding them to a pub/sub queue (think System.Threading.Channels or BlockingCollection<T>) which fits naturally with the producer/consumer pattern.

Alternatively, it is acceptable to use async void for cases where you need to await inside your handlers (see THIS, THIS and THIS).

HTH.

@NimaAra NimaAra self-assigned this Oct 29, 2020
@valdisiljuconoks
Copy link
Author

Thx, think we will pump into a channel then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants