-
-
Notifications
You must be signed in to change notification settings - Fork 25
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 for each handling #16
Conversation
…e scoped objects are disposed.
…rds at the same time. Also added example SNS ForEachAsync example
Hey @wcrooy! Thank you for your PR. It's a really nice addition. I wonder whether these extensions should be in a side-package that can be added on the side. What do you think? |
Hi @Kralizek. |
Hi @Kralizek , Regards, Wouter |
Hi @wcrooy, sorry. just busy these days. Is it urgent for you? |
I'll try to work on it sometimes today. It generally looks really good. |
@wcrooy do you think it's a correct assumption to say that if If so, we could merge the two extensions into one. public static IServiceCollection UseNotificationHandler<TNotification, THandler>(this IServiceCollection services, int maxDegreeOfParallelism = 1)
where TNotification : class
where THandler : class, INotificationHandler<TNotification>
{
if (maxDegreeOfParallelism <= 0)
{
throw new ArgumentOutOfRangeException(nameof(maxDegreeOfParallelism), $"{nameof(maxDegreeOfParallelism)} can't be less than 1");
}
if (maxDegreeOfParallelism > 1)
{
services.AddSingleton(new ForEachAsyncHandlingOption { MaxDegreeOfParallelism = maxDegreeOfParallelism });
services.AddTransient<IEventHandler<SNSEvent>, SnsForEachAsyncEventHandler<TNotification>>();
}
else
{
services.AddTransient<IEventHandler<SNSEvent>, SnsEventHandler<TNotification>>();
}
services.AddTransient<INotificationHandler<TNotification>, THandler>();
return services;
} |
@wcrooy please review the changes I introduced in the latest commit. I think it makes a clearer API. This is the idea: // Non-parallel execution (implicit)
services.UseNotificationHandler<CustomNotification, CustomNotificationHandler>();
// Non-parallel execution (explicit)
services.UseNotificationHandler<CustomNotification, CustomNotificationHandler>(enableParallelExecution: false);
// Parallel execution, max parallelism set to available CPU count
services.UseNotificationHandler<CustomNotification, CustomNotificationHandler>(enableParallelExecution: true);
// Parallel execution, max parallelism set to specific value
services.ConfigureSnsParallelExecution(4);
services.UseNotificationHandler<CustomNotification, CustomNotificationHandler>(enableParallelExecution: true); Similarly for SQS. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! Thanks! I like them. :-)
This PR contains the possibility to handle multiple records at the same time. Based on mem-usage the degree of parallelism can be set.
Let me know if you've got any further questions or remarks.