Skip to content

Commit 2dfef86

Browse files
committed
i forgot why cotask existed
1 parent be8b015 commit 2dfef86

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

tutorials/coroutines.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Task<std::string, int> someTask() {
3737
}
3838
```
3939

40-
One problem that stems from using Task for asynchronous handling is that it cannot support void. Sometimes you want a function to run asynchronously without returning a value, and for that we introduce `coro::CoTask`. CoTask is exactly like Task but it allows void:
40+
One problem that stems from using Task for asynchronous handling is that it has the `[[nodiscard]]` attribute. Often times, you want a coroutine without any given return value, which leads to annoyances with compiler warnings. `coro::CoTask` is the solution to this, as it's a discardable wrapper around Task:
4141

4242
```cpp
4343
#include <Geode/utils/web.hpp>
@@ -49,6 +49,8 @@ coro::CoTask<void> logResponseCode() {
4949

5050
log::info("Response code: {}", res.code());
5151
}
52+
53+
logResponseCode(); // No warning
5254
```
5355

5456
Creating a new function for just the asynchronous bits might get tedious. Luckily, you don't have to with the `$async` macro:

0 commit comments

Comments
 (0)