Created
January 9, 2020 19:49
-
-
Save markpapadakis/073cf8b6c2ad89b60d76774bdece3252 to your computer and use it in GitHub Desktop.
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
// contrived example | |
task<int> fun_with_coroutines() { | |
auto fd = co_await async_open("/tmp/file.txt", O_RDONLY); | |
if (-1 == fd) { | |
co_return - 1; | |
} | |
char buf[16]; | |
if (const auto res = co_await async_read(fd, buf, sizeof(buf)); res != sizeof(buf)) { | |
close(fd); | |
co_return - 1; | |
} | |
close(fd); | |
try { | |
co_await transmit_junk(co_await async_connect("localhost:5121"), buf, sizeof(buf)); | |
} catch (...) { | |
co_return - 1; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment