-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lessen overhead of calling non-coroutine functions with Task<T> retur…
…n type. Corral currently provides `noop()` for creating degenerate Task<void> not backed by a coroutine, useful when a function which is not a coroutine has to return Task<void> (say, to conform to an abstract interface). Sadly, there's no equivalent for synchronous functions returning a non-void value: struct AsyncStream { Task<void> close() = 0; Task<size_t> read(std::span<char> buf) = 0; }; struct MemStream: AsyncStream { // Fast to call, no coroutine frame allocated Task<void> close() override { return noop(); } // Even there aren't any suspension points here, // still allocate a coroutine frame and pay the full price Task<size_t> read(std::span<char> buf) override { memcpy(...); co_return buf.size(); } }; This diff addresses that, introducing a new `Task<T> just(T)` function, which wraps a value into a Task which would yield the value when `co_await`ed, allowing to rewrite the above snippet as Task<size_t> read(std::span<char> buf) override { memcpy(...); return corral::just(buf.size()); }
- Loading branch information
1 parent
1f18406
commit 2ef41e4
Showing
5 changed files
with
142 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters