Coroutine Guide
Starting from LeviLamina 1.0.0, coroutines replace the Scheduler.
Usage
- Include the header files:
C++ 1 2
#include "ll/api/chrono/GameChrono.h" #include "ll/api/coro/CoroTask.h" - Call
ll::coro::keepThisin a function, passing a lambda function that returnsll::coro::CoroTask. - Call the
launchorsyncLaunchmethod afterkeepThis, the latter will block server thread, passing anExecutorclass, such asll::thread::ServerThreadExecutor.
Available Executors
ll::thread::ServerThreadExecutor (ll/api/thread/ServerThreadExecutor.h): Server thread
ll::thread::ThreadPoolExecutor (ll/api/thread/ThreadPoolExecutor.h): Thread pool
For more Executors, refer to ll/api/thread/.
Examples
ServerThreadExecutor
The following function uses a coroutine to print a string to the console every 20 ticks on the server thread, for a total of 20 times.
| C++ | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
ThreadPoolExecutor
The following function uses a coroutine to print a string to the console every second in the thread pool, for a total of 20 times.
| C++ | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |