@@ -103,7 +103,8 @@ I have also learned about some well-known C++20 coroutine open-source libraries,
103103| Name | Description |
104104| ----------------------------------------------| -------------------------------------------------------|
105105| ` coro::async<T> ` | Async task type, supports ` co_await ` and ` co_return ` |
106- | ` coro::co_spawn(executor, awaitable) ` | Spawn a coroutine on an executor |
106+ | ` coro::spawn(executor, awaitable) ` | Spawn a coroutine on an executor |
107+ | ` coro::spawn_local(awaitable) ` | Spawn a coroutine on the current executor |
107108| ` coro::when_all(awaitables...) -> awaitable ` | Wait for all tasks to complete |
108109| ` coro::when_any(awaitables...) -> awaitable ` | Wait for any task to complete |
109110| ` coro::sleep(duration) ` | Async wait for specified duration (chrono duration) |
@@ -185,15 +186,20 @@ async<void> process() {
185186
186187int main () {
187188 executor_loop executor;
188-
189- // Launch coroutine
190- co_spawn (executor, process());
189+
190+ // Launch coroutine on specific executor
191+ spawn (executor, process());
191192 // Or: process().detach(executor);
192193
193194 // Run event loop
194195 executor.run_loop();
195196 return 0;
196197}
198+
199+ // Using spawn_local inside coroutine
200+ async<void > main_task () {
201+ co_await spawn_local(process());
202+ }
197203```
198204
199205### Launch Coroutine with Callback
@@ -536,9 +542,8 @@ async<void> consumer(channel<int>& ch) {
536542async<void > example() {
537543 channel<int > ch; // Unbuffered channel
538544
539- auto& exec = *co_await current_executor();
540- co_spawn(exec, producer(ch));
541- co_spawn(exec, consumer(ch));
545+ co_await spawn_local(producer(ch));
546+ co_await spawn_local(consumer(ch));
542547}
543548```
544549
@@ -578,12 +583,10 @@ async<void> broadcast_example() {
578583 }
579584 };
580585
581- auto& exec = *co_await current_executor();
582-
583586 // Spawn multiple receivers
584- co_spawn (exec, receiver(ch, 1));
585- co_spawn(exec, receiver(ch, 2));
586- co_spawn(exec, receiver(ch, 3));
587+ co_await spawn_local( receiver(ch, 1));
588+ co_await spawn_local( receiver(ch, 2));
589+ co_await spawn_local( receiver(ch, 3));
587590
588591 // Broadcasting sends the value to ALL waiting receivers
589592 size_t notified_count = co_await ch.broadcast(42);
@@ -623,8 +626,8 @@ async<void> example() {
623626 wg.add(2);
624627
625628 // Launch worker coroutines
626- co_spawn (executor, worker_task(wg, "Worker1", 100));
627- co_spawn (executor, worker_task(wg, "Worker2", 150));
629+ spawn (executor, worker_task(wg, "Worker1", 100));
630+ spawn (executor, worker_task(wg, "Worker2", 150));
628631
629632 // Wait for all operations to complete
630633 co_await wg.wait();
0 commit comments