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

PublishAsync should just publish, not wait for handlers execution #38

Open
maxiptah opened this issue Jul 21, 2021 · 1 comment
Open

Comments

@maxiptah
Copy link

maxiptah commented Jul 21, 2021

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
Copy link
Contributor

You could use Publish or you could hold the task and await after the code you need to fire immediately.

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

No branches or pull requests

2 participants