PublishAsync should just publish, not wait for handlers execution
maxiptah opened this issue · 1 comments
maxiptah commented
I'm expecting events behavior from PubSub, i.e. if I publish an event, somebody will catch it eventually (or not) and do what needs to be done. I was really surprised that it waits for all handlers to finish, i.e. Publish won't return until all handlers are done.
PubSub.Hub.Default.Subscribe<MyObj>(async c =>
{
await Task.Delay(TimeSpan.FromSeconds(10));
});
await PubSub.Hub.Default.PublishAsync(new MyObj());
var t = 1; // We reach this line only after the delay func is finished, i.e. in 10 seconds.
I would excpect that the above code behaves like this:
PubSub.Hub.Default.Subscribe<MyObj>(c =>
{
_ = Task.Run(async () => await Task.Delay(TimeSpan.FromSeconds(10)));
});
await PubSub.Hub.Default.PublishAsync(new MyObj());
var t = 1; // We reach this line immideatelly. Handler task will be finished at some point in time.
kevmoens commented
You could use Publish or you could hold the task and await after the code you need to fire immediately.