Skip to content

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

@maxiptah

Description

@maxiptah

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions