{"id":22760683,"url":"https://github.com/funatsufumiya/ofxasync","last_synced_at":"2025-10-08T22:22:55.571Z","repository":{"id":69043728,"uuid":"166248168","full_name":"funatsufumiya/ofxAsync","owner":"funatsufumiya","description":"Simple asynchronous function runnner, using ofThread","archived":false,"fork":false,"pushed_at":"2025-04-12T06:40:47.000Z","size":27,"stargazers_count":6,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-28T21:46:35.249Z","etag":null,"topics":["openframeworks-addon"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/funatsufumiya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2019-01-17T15:27:36.000Z","updated_at":"2025-04-12T06:40:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"78c5a3ea-9dee-45c4-b0a9-510214152ce7","html_url":"https://github.com/funatsufumiya/ofxAsync","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/funatsufumiya/ofxAsync","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funatsufumiya%2FofxAsync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funatsufumiya%2FofxAsync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funatsufumiya%2FofxAsync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funatsufumiya%2FofxAsync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/funatsufumiya","download_url":"https://codeload.github.com/funatsufumiya/ofxAsync/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funatsufumiya%2FofxAsync/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267780417,"owners_count":24143204,"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","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["openframeworks-addon"],"created_at":"2024-12-11T09:08:08.793Z","updated_at":"2025-10-08T22:22:55.553Z","avatar_url":"https://github.com/funatsufumiya.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ofxAsync\n\n- openFrameworks addon for 0.9.8 - 0.12.0\n- Simple ofThread wrapper for easier multi-threading.\n    - **Please that this is not real concurrent / asynchronous library like [asyncio](https://github.com/netcan/asyncio). Just thread wrapper.**\n    - If you need real concurrent / asynchronous library, you should consider [ofxTaskRunner](https://github.com/funatsufumiya/ofxTaskRunner) instead.\n\n## Comparison to [ofxTaskRunner](https://github.com/funatsufumiya/ofxTaskRunner)\n\n`ofxTaskRunner` provides chainable methods which describes time-driven actions, while `ofxAsync` only provides simple thread wrapper.\n\n`ofxTaskRunner` runs on single (main) thread, so you can use normal GL functions with asynchronous style. `ofxAsync` triggers real multi-thread, so it is useful hard time-taken tasks.\n\n## Usage\n\nThe simplest example:\n\n```cpp\nofxAsync::run([\u0026](){\n    // anything you want to make parallel\n\n    ofSleepMillis(5000); // (ex) a task which takes time \n    ofLog() \u003c\u003c \"done! after 5 sec!\";\n});\n\nofLog() \u003c\u003c \"task started.\";\n\n// == logs ======\n// [notice ] task started.\n// [notice ] done! after 5 sec!\n```\n\nAnother example with parameters:\n\n```cpp\nfor(int i=0; i\u003c20; ++i){\n    ofxAsync::run([i](){ // \u003c- capture variable i by copy\n        ofSleepMillis(ofRandom(100,300));\n        ofLog() \u003c\u003c \"thread No.\" \u003c\u003c i;\n    });\n}\n\n// == logs ======\n// [notice ] thread No.9\n// [notice ] thread No.13\n// [notice ] thread No.7\n// [notice ] thread No.11\n// ...\n// [notice ] thread No.15\n// [notice ] thread No.3\n```\n\n( NOTE: about the **variable capture**, please read [this](https://en.cppreference.com/w/cpp/language/lambda) or other pages )\n\n\nAnd more, `ofThread*` can be used as an argument:\n\n```cpp\n// Task cancelling example:\n\nint thread_id = ofxAsync::run([\u0026](ofThread* thread){\n    for(int i=0; i\u003c10; ++i){\n\n        ofLog() \u003c\u003c \"processing \" \u003c\u003c (i+1) \u003c\u003c \" / 10\";\n        ofSleepMillis(1000);\n\n        // cancell tasks when not running\n        if(!thread-\u003eisThreadRunning()){\n            ofLog() \u003c\u003c \"task cancelled\";\n            return;\n        }\n    }\n\n    ofLog() \u003c\u003c \"done!\";\n});\n\nofLog() \u003c\u003c \"task started\";\nofSleepMillis(3000);\nofxAsync::stop(thread_id); // Cancel task after 3 seconds\n\n// == logs ======\n// [notice ] task started\n// [notice ] processing 1 / 10\n// [notice ] processing 2 / 10\n// [notice ] processing 3 / 10\n// [notice ] task cancelled\n```\n\n## ofxAsyncInstance\n\nThis is instance-based version of ofxAsync.\nFunctionally same as ofxAsync, but you can use it as an instance.\n\nThis is useful when you want to manage multiple threads in a class.\n\nNOTE: `ofxAsync::stopAll()` and `ofxAsync::waitForAll()` won't affect to ofxAsyncInstance. ofxAsync and ofxAsyncInstance are completely independent.\n\n```cpp\n// ofApp.h\n#include \"ofxAsyncInstance.h\"\n\nclass ofApp : public ofBaseApp{\n    // ....\n    ofxAsyncInstance asyncInstance;\n}\n\n// ofApp.cpp\nvoid ofApp::setup(){\n    asyncInstance.run([](){\n        ofLog() \u003c\u003c \"thread 1\";\n    });\n\n    asyncInstance.run([](){\n        ofLog() \u003c\u003c \"thread 2\";\n    });\n\n    asyncInstance.waitForAll();\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffunatsufumiya%2Fofxasync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffunatsufumiya%2Fofxasync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffunatsufumiya%2Fofxasync/lists"}