-
Notifications
You must be signed in to change notification settings - Fork 777
Open
Description
I've been working under the assumption that if I await a call to PublishOnBackgroundThreadAsync, then I'm actually awaiting for all the handlers to run on all the subscribers. It turns out that's not the case. If it was a bad assumption on my part, then maybe the docs could clarify, or maybe it's just a bug?
Here's the current version:
public static Task PublishOnBackgroundThreadAsync(this IEventAggregator eventAggregator, object message, CancellationToken cancellationToken)
{
return eventAggregator.PublishAsync(
message,
f => Task.Factory.StartNew(f, default, TaskCreationOptions.None, TaskScheduler.Default),
cancellationToken
);
}
Here's a version which DOES wait for all the handlers to run:
public static Task PublishOnBackgroundThreadAsync_WithUnwrap(this IEventAggregator eventAggregator, object message, CancellationToken cancellationToken)
{
return eventAggregator.PublishAsync(
message,
f => Task.Factory.StartNew(f, default, TaskCreationOptions.None, TaskScheduler.Default).Unwrap(),
cancellationToken
);
}
Note the .Unwrap() as the only difference. Basically the original version is returning a Task<Task>
Thanks for your work on this library!!
Metadata
Metadata
Assignees
Labels
No labels