lewissbaker / cppcoro

A library of C++ coroutine abstractions for the coroutines TS
MIT License
3.43k stars 472 forks source link

Add blocking 'sync_wait(task)' function for synchronously waiting for a task to complete #27

Closed lewissbaker closed 7 years ago

lewissbaker commented 7 years ago

Added lightweight_manual_reset_event class in 278c3181a68e04a206071a4de5c2ec1f3c79d429 that should serve as a building-block for a synchronous blocking API for tasks.

The implementation of wait_for() should then be able to attach a continuation to the task that calls event.set() when it completes and then just blocks waiting for the task to complete by calling event.wait().

lewissbaker commented 7 years ago

Bikeshedding: wait_for() - could be confused with waiting/sleeping for a specified time? sync_wait() blocking_wait() wait() - maybe not obvious enough that it is blocking?

lewissbaker commented 7 years ago

Commit 3a581e633e19c1f2aeb199fd20df99cf545419f3 has added the cppcoro::sync_wait() function.

It uses cppcoro::detail::lightweight_manual_reset_event (added in d6f005342d889f3567ff818023610bd1aca11232) to do the blocking wait. This uses futex() / WaitOnAddress() under the hood to do the blocking-wait.

lewissbaker commented 7 years ago

This is just waiting on some documentation in the README.