Cooperative multitasking primitives built on cortex::Coroutine.
More...
Cooperative multitasking primitives built on cortex::Coroutine.
This module provides fiber-based cooperative multitasking that works on both native and WebAssembly platforms without any threading.
Quick Start
return 42;
});
int result = future.
Get();
});
return 0;
}
Handle to a spawned fiber that returns a value.
Definition future.hpp:46
T Get()
Block until fiber completes and return the result.
Definition future.hpp:97
static void Run(F &&entry)
Run the scheduler with an initial fiber.
Definition scheduler.hpp:199
auto Spawn(F &&func, std::size_t stack_size) -> Future< std::invoke_result_t< F > >
Spawn a new fiber with custom stack size.
Definition future.hpp:284
void Yield()
Yield control to other ready fibers.
Convenience header that includes all tiny_fiber components.
Components
◆ IsStopping()
| bool cortex::tiny_fiber::IsStopping |
( |
| ) |
|
Check if the current scheduler is stopping.
Fibers can use this to exit gracefully during shutdown.
- Returns
- true if the scheduler is stopping, false otherwise.
- Exceptions
-
| std::logic_error | if called outside of a fiber. |
◆ Lock()
Create a lock guard for the mutex.
- Parameters
-
- Returns
- A Guard that will unlock the mutex on destruction.
◆ Spawn() [1/2]
| auto cortex::tiny_fiber::Spawn |
( |
F && |
func | ) |
-> Future<std::invoke_result_t<F>> |
Spawn a new fiber.
- Parameters
-
| func | The function to execute in the fiber. |
- Returns
- A Future to wait for the result.
◆ Spawn() [2/2]
| auto cortex::tiny_fiber::Spawn |
( |
F && |
func, |
|
|
std::size_t |
stack_size |
|
) |
| -> Future<std::invoke_result_t<F>> |
Spawn a new fiber with custom stack size.
- Parameters
-
| func | The function to execute in the fiber. |
| stack_size | The stack size for the fiber. |
- Returns
- A Future to wait for the result.
◆ Yield()
| void cortex::tiny_fiber::Yield |
( |
| ) |
|
Yield control to other ready fibers.
The current fiber is placed at the back of the ready queue. Must be called from within a fiber.
- Exceptions
-
◆ YieldIfOthersReady()
| bool cortex::tiny_fiber::YieldIfOthersReady |
( |
| ) |
|
Yield only if there are other ready fibers.
- Returns
- true if yielded, false if no other fibers are ready.
- Exceptions
-