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

Send Message to All Users at once #54

Open
masoudamidi opened this issue Mar 9, 2019 · 1 comment
Open

Send Message to All Users at once #54

masoudamidi opened this issue Mar 9, 2019 · 1 comment
Milestone

Comments

@masoudamidi
Copy link

Hello,
First of all thank you for your best library.
I wanted to send push notification to all users at once. But SendNotification method just gets 1 Subscription at a time. can you develope it to get list of Subscriptions ?

@coryjthompson coryjthompson added this to the 1.1.0 milestone Mar 16, 2019
@web-push-libs web-push-libs deleted a comment from nani900036 Feb 6, 2024
@au5ton
Copy link

au5ton commented Feb 6, 2024

This is likely something that can be done in your calling code like so (needs to be adapted to this library):

Source: https://stackoverflow.com/a/10810730

public async Task MyOuterMethod()
{
    // let's say there is a list of 1000+ URLs
    var urls = { "http://google.com", "http://yahoo.com", ... };

    // now let's send HTTP requests to each of these URLs in parallel
    var allTasks = new List<Task>();
    var throttler = new SemaphoreSlim(initialCount: 20);
    foreach (var url in urls)
    {
        // do an async wait until we can schedule again
        await throttler.WaitAsync();

        // using Task.Run(...) to run the lambda in its own parallel
        // flow on the threadpool
        allTasks.Add(
            Task.Run(async () =>
            {
                try
                {
                    var client = new HttpClient();
                    var html = await client.GetStringAsync(url);
                }
                finally
                {
                    throttler.Release();
                }
            }));
    }

    // won't get here until all urls have been put into tasks
    await Task.WhenAll(allTasks);

    // won't get here until all tasks have completed in some way
    // (either success or exception)
}

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

3 participants