Add folly::coro::Baton implementation
Summary: Adds a fundamental thread-synchronisation primitive for coroutines that allows one or more coroutines to suspend execution until some thread signals them. This differs from the folly::fibers::Baton implementation in that it does not expose a blocking wait API, only an asynchronous wait API that must be waited-on from within a coroutine. This implementation also permits multiple coroutines concurrently waiting on the baton. Example usage: ```c++ folly::coro::Baton baton; std::string sharedValue; folly::coro::Task<void> consumer() { // Wait until the baton is posted. co_await baton.waitAsync(); // Now safe to read shared state. std::cout << sharedValue << std::cout; } void producer() { // Write to shared state sharedValue = "some result"; // Publish the value by 'posting' the baton. // This will resume the consumer if it was currently suspended. baton.post(); } ``` Reviewed By: andriigrynenko Differential Revision: D9208955 fbshipit-source-id: 07aa372b4c6b90dc0565763add716e591d312c65
Showing
Please register or sign in to comment