{"id":22438557,"url":"https://github.com/SiddiqSoft/asynchrony","last_synced_at":"2025-08-01T16:34:22.731Z","repository":{"id":46541350,"uuid":"407301947","full_name":"SiddiqSoft/asynchrony","owner":"SiddiqSoft","description":"Classes to allow you to build asynchrony in your applications using standard C++ jthread, semaphore, deque","archived":false,"fork":false,"pushed_at":"2024-10-28T04:27:57.000Z","size":121,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-12-06T01:10:38.016Z","etag":null,"topics":["asynchronous-programming","cpp","cpp20","nuget","periodic-invocation","thread-pool","worker-pool"],"latest_commit_sha":null,"homepage":"https://siddiqsoft.github.io/asynchrony-lib/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SiddiqSoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-16T20:14:02.000Z","updated_at":"2024-10-28T04:24:08.000Z","dependencies_parsed_at":"2024-10-28T07:12:41.093Z","dependency_job_id":null,"html_url":"https://github.com/SiddiqSoft/asynchrony","commit_stats":null,"previous_names":["siddiqsoft/asynchrony","siddiqsoft/asynchrony-lib"],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SiddiqSoft%2Fasynchrony","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SiddiqSoft%2Fasynchrony/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SiddiqSoft%2Fasynchrony/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SiddiqSoft%2Fasynchrony/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SiddiqSoft","download_url":"https://codeload.github.com/SiddiqSoft/asynchrony/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228393618,"owners_count":17912865,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asynchronous-programming","cpp","cpp20","nuget","periodic-invocation","thread-pool","worker-pool"],"created_at":"2024-12-06T01:10:42.415Z","updated_at":"2025-08-01T16:34:22.720Z","avatar_url":"https://github.com/SiddiqSoft.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"asynchrony : Add asynchrony to your apps\n-------------------------------------------\n\u003c!-- badges --\u003e\n[![Build Status](https://dev.azure.com/siddiqsoft/siddiqsoft/_apis/build/status/SiddiqSoft.asynchrony?branchName=main)](https://dev.azure.com/siddiqsoft/siddiqsoft/_build/latest?definitionId=17\u0026branchName=main)\n![](https://img.shields.io/nuget/v/SiddiqSoft.asynchrony)\n![](https://img.shields.io/github/v/tag/SiddiqSoft/asynchrony)\n![](https://img.shields.io/azure-devops/tests/siddiqsoft/siddiqsoft/17)\n\u003c!-- end badges --\u003e\n\n# Motivation\n- We needed to add asynchrony to our code.\n- The code here is a set of helpers that utilize the underlying deque, semaphore, mutex features found in std.\n- Be instructive while providing functional code\n- Use only C++20 standard code: jthread, deque, semaphore, barriers and latch\n\n# Usage\n\n\u003e Requires C++20 support!\n\u003e\n\u003e Specifically we require `jthread` and `stop_token` support which is unfortunately not available in the Apple Clang 16 version. This library works with gcc 14+ or MSVC 17+ or Clang 18+.\n\nRefer to the [documentation](https://siddiqsoft.github.io/asynchrony/) for details.\n\nThe library uses concepts to ensure the type `T` meets move construct requirements.\n\n## Single threaded worker\n\n```cpp\n#include \"siddiqsoft/simple_worker.hpp\"\n\n// Define your data\nstruct MyWork\n{\n   std::string urlDestination{};\n   std::string data{};\n   void operator()(){\n      magic_post_to(urlDestination, data);\n   }\n};\n\nvoid main()\n{\n   // Declare worker with our data type and the driver function.\n   siddiqsoft::simple_worker\u003cMyWork\u003e worker{[](auto\u0026 item){\n                                              // call the item's operator()\n                                              // to invoke actual work.\n                                              item();\n                                           }};\n   // Fire 100 items\n   for( int i=0; i \u003c 100; i++ )\n   {\n      // Queues into the single worker\n      worker.queue({std::format(\"https://localhost:443/test?iter={}\",i),\n                    \"hello-world\"});\n   }\n\n   // As the user, you must control the lifetime of the worker\n   // Trying to delete the worker will cause it to stop\n   // and abandon any items in the internal deque.\n   std::this_thread::sleep_for(1s);\n}\n\n```\n\n## Multi-threaded worker pool\n\n```cpp\n#include \"siddiqsoft/simple_pool.hpp\"\n\nvoid main()\n{\n   // Declare worker with our data type and the driver function.\n   siddiqsoft::simple_pool\u003cMyWork\u003e worker{[](auto\u0026 item){\n                                           // call the item's operator()\n                                           // to invoke actual work.\n                                           item();\n                                        }};\n   // Fire 100 items\n   for( int i=0; i \u003c 100; i++ )\n   {\n      // Queues into the single queue but multiple worker threads\n      // (defaults to CPU thread cout)\n      worker.queue({std::format(\"https://localhost:443/test?iter={}\",i),\n                    \"hello-world\"});\n   }\n\n   // As the user, you must control the lifetime of the worker\n   // Trying to delete the worker will cause it to stop\n   // and abandon any items in the internal deque.\n   std::this_thread::sleep_for(1s);\n}\n```\n\n\n## Multi-threaded roundrobin pool\n\n```cpp\n#include \"siddiqsoft/roundrobin_pool.hpp\"\n\nvoid main()\n{\n   // Declare worker with our data type and the driver function.\n   siddiqsoft::roundrobin_pool\u003cMyWork\u003e worker{[](auto\u0026 item){\n                                               // call the item's operator()\n                                               // to invoke actual work.\n                                               item();\n                                             }};\n   // Fire 100 items\n   for( int i=0; i \u003c 100; i++ )\n   {\n      // Queues into the thread pools individual queue by round-robin\n      // across the threads with simple counter.\n      // (defaults to CPU thread cout)\n      worker.queue({std::format(\"https://localhost:443/test?iter={}\",i),\n                    \"hello-world\"});\n   }\n\n   // As the user, you must control the lifetime of the worker\n   // Trying to delete the worker will cause it to stop\n   // and abandon any items in the internal deque.\n   std::this_thread::sleep_for(1s);\n}\n```\n\n## Resource Pool\n\nProvides a basic resource pool useful for keeping a pool of connection objects for the various threadpools to checkout/checkin.\n\n```cpp\nnamespace siddiqsoft {\n    template\u003ctypename T\u003e\n    class resource_pool {\n        public:\n        auto getCapacity();\n        [[nodiscard]] T checkout(); /* throw() */\n        void checkin(T\u0026\u0026 rsrc);\n    };\n}\n```\n\n## Implementation note\nIn order to use `std::jthread` on Clang 18 and Clang 19, we enable the compiler flag `\"CMAKE_CXX_FLAGS\": \"-fexperimental-library\"` in the CMakeLists.txt. This option will show up in your client library under Clang compilers.\n\n\u003cp align=\"right\"\u003e\n\u0026copy; 2021 Siddiq Software LLC. All rights reserved.\n\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSiddiqSoft%2Fasynchrony","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSiddiqSoft%2Fasynchrony","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSiddiqSoft%2Fasynchrony/lists"}