{"id":15047467,"url":"https://github.com/coyorkdow/cfuture","last_synced_at":"2025-12-30T10:44:30.021Z","repository":{"id":222629489,"uuid":"756666391","full_name":"coyorkdow/cfuture","owner":"coyorkdow","description":"a c++ promise future implementation with continuation [work in progress]","archived":false,"fork":false,"pushed_at":"2024-03-29T06:53:04.000Z","size":51,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-03-29T07:46:58.053Z","etag":null,"topics":["async","concurrency","cpp","cpp14"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coyorkdow.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}},"created_at":"2024-02-13T04:07:36.000Z","updated_at":"2024-04-14T21:26:16.345Z","dependencies_parsed_at":null,"dependency_job_id":"9b2b782c-9c32-4e0a-87cf-b1fee00fba54","html_url":"https://github.com/coyorkdow/cfuture","commit_stats":null,"previous_names":["coyorkdow/cfuture"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coyorkdow%2Fcfuture","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coyorkdow%2Fcfuture/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coyorkdow%2Fcfuture/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coyorkdow%2Fcfuture/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coyorkdow","download_url":"https://codeload.github.com/coyorkdow/cfuture/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243475328,"owners_count":20296714,"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":["async","concurrency","cpp","cpp14"],"created_at":"2024-09-24T20:58:49.039Z","updated_at":"2025-12-30T10:44:29.972Z","avatar_url":"https://github.com/coyorkdow.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cfuture\nA promise future implementation with continuation.\n\ncfuture is **header-only**, and it only has a **single file** `cfuture.hpp`. It requires cpp14.\n\n# Motivation\n\ncfuture is aimed to provide a promise/future class which supports `future::then` to attach the continuations like a chain. I admit that async/await is a better practice than promise/future when writing the asynchronous codes. But there are still a lot of projects cannot use c++20 or higher standard. Or, sometimes, the promise/future is easier than coroutine.\n\nThe `boost::future` and `std::experimental::future` (in concurrency TS) both support `then`. But I hope to provide a light and easy-to-rely implementation. It isn't the cfuture's goal to be completely complied with the design of `std::future` or `boost::future`. But still, it will very close to them. It could be an alternate in most cases.\n\n# Quick Start\n\n```cpp\n  using namespace std::chrono_literals;\n  using namespace cfuture;\n  Promise\u003cint\u003e p;\n  std::cout \u003c\u003c \"the main thread is \" \u003c\u003c std::this_thread::get_id() \u003c\u003c '\\n';\n  std::thread th([\u0026] {\n    std::cout \u003c\u003c \"run in thread \" \u003c\u003c std::this_thread::get_id() \u003c\u003c '\\n';\n    std::this_thread::sleep_for(100ms);\n    p.set_value(1);\n  });\n  Future\u003cstd::string\u003e f;\n  f = p.get_future()\n          .then([](Future\u003cint\u003e v) {\n            Promise\u003cint\u003e p;\n            auto future = p.get_future();\n            std::thread th([v = v.get(), p = std::move(p)]() mutable {\n              std::cout \u003c\u003c \"run in thread \" \u003c\u003c std::this_thread::get_id() \u003c\u003c '\\n';\n              std::this_thread::sleep_for(100ms);\n              p.set_value(v + 2);\n            });\n            th.detach();\n            return future;\n          })\n          .then([](Future\u003cint\u003e v) -\u003e long {\n            std::cout \u003c\u003c \"run in thread \" \u003c\u003c std::this_thread::get_id() \u003c\u003c '\\n';\n            std::this_thread::sleep_for(1ms);\n            return v.get() + 3;\n          })\n          .then([](Future\u003clong\u003e v) {\n            std::cout \u003c\u003c \"run in thread \" \u003c\u003c std::this_thread::get_id() \u003c\u003c '\\n';\n            std::this_thread::sleep_for(1ms);\n            return std::to_string(v.get() + 4);\n          });\n  std::cout \u003c\u003c f.get() \u003c\u003c '\\n';\n  th.join();\n```\n\nThe possible output of the above codes is\n```\nthe main thread is 0x7ff857913340\nrun in thread 0x70000da84000\nrun in thread 0x70000db07000\nrun in thread 0x70000db07000\nrun in thread 0x70000db07000\n10\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoyorkdow%2Fcfuture","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoyorkdow%2Fcfuture","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoyorkdow%2Fcfuture/lists"}