Add asynchrony to your apps
$ dotnet add package SiddiqSoft.asynchrony-libRefer to the documentation for details.
The library uses concepts to ensure the type T meets move construct requirements.
#include "siddiqsoft/asynchrony-lib.hpp"
// Define your data
struct MyWork
{
std::string urlDestination{};
std::string data{};
void operator()(){
magic_post_to(urlDestination, data);
}
};
void main()
{
// Declare worker with our data type and the driver function.
siddiqsoft::simple_worker<MyWork> worker{[](auto& item){
// call the item's operator()
// to invoke actual work.
item();
}};
// Fire 100 items
for( int i=0; i < 100; i++ )
{
// Queues into the single worker
worker.queue({std::format("https://localhost:443/test?iter={}",i),
"hello-world"});
}
// As the user, you must control the lifetime of the worker
// Trying to delete the worker will cause it to stop
// and abandon any items in the internal deque.
std::this_thread::sleep_for(1s);
}
#include "siddiqsoft/simple_pool.hpp"
void main()
{
// Declare worker with our data type and the driver function.
siddiqsoft::simple_pool<MyWork> worker{[](auto& item){
// call the item's operator()
// to invoke actual work.
item();
}};
// Fire 100 items
for( int i=0; i < 100; i++ )
{
// Queues into the single queue but multiple worker threads
// (defaults to CPU thread cout)
worker.queue({std::format("https://localhost:443/test?iter={}",i),
"hello-world"});
}
// As the user, you must control the lifetime of the worker
// Trying to delete the worker will cause it to stop
// and abandon any items in the internal deque.
std::this_thread::sleep_for(1s);
}
#include "siddiqsoft/roundrobin_pool.hpp"
void main()
{
// Declare worker with our data type and the driver function.
siddiqsoft::roundrobin_pool<MyWork> worker{[](auto& item){
// call the item's operator()
// to invoke actual work.
item();
}};
// Fire 100 items
for( int i=0; i < 100; i++ )
{
// Queues into the thread pools individual queue by round-robin
// across the threads with simple counter.
// (defaults to CPU thread cout)
worker.queue({std::format("https://localhost:443/test?iter={}",i),
"hello-world"});
}
// As the user, you must control the lifetime of the worker
// Trying to delete the worker will cause it to stop
// and abandon any items in the internal deque.
std::this_thread::sleep_for(1s);
}
<p align="right">
© 2021 Siddiq Software LLC. All rights reserved.
</p>