Skip to content

Commit 32ae0bb

Browse files
committed
pass lambdas instead of futures to spawn
1 parent bee6092 commit 32ae0bb

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

tutorials/migrate-v5.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ async::spawn(
100100
This will behave similar to original, it will spawn `file::pick()` on the async runtime, and once completed, call the provided callback on the main thread. If you want more control over what happens (such as not calling your function on main thread), you can use the `Runtime` directly:
101101
```cpp
102102
arc::Runtime& rt = async::runtime();
103-
auto handle = rt.spawn([](this auto self) -> arc::Future<> {
103+
auto handle = rt.spawn([] -> arc::Future<> {
104104
auto result = co_await file::pick(...);
105105
if (result.isOk()) {
106106
auto path = result.unwrap();
107107
}
108-
}());
108+
});
109109
```
110110

111111
If you've instead used listeners, a `async::TaskHolder` class was added which has a similar API. For example, the following v4 code that makes requests:
@@ -167,12 +167,12 @@ Async tasks are the most common ones, and they are useful for pretty much any co
167167
```cpp
168168
auto [tx, rx] = arc::mpsc::channel<int>();
169169

170-
auto handle = async::runtime().spawn([](auto rx) -> arc::Future<> {
170+
auto handle = async::runtime().spawn([rx = std::move(rx)] -> arc::Future<> {
171171
while (auto result = co_await rx.recv()) {
172172
log::debug("Got value: {}", std::move(result).unwrap());
173173
co_await arc::sleep(asp::Duration::fromMillis(100));
174174
}
175-
}(std::move(rx)));
175+
});
176176

177177
// Then, in regular, sync code you can use the mpsc channel to communicate with the worker
178178
(void) tx.trySend(1);

0 commit comments

Comments
 (0)