eve.rt.scheduler
Fiber Scheduler with EventLoop Integration
This module provides a cooperative fiber scheduler that integrates with the EVE event loop. The scheduler manages a collection of fibers and multiplexes their execution, automatically yielding to the event loop when fibers are waiting for I/O or timers.
Copyright
Types 4
Status of a scheduled task.
A handle to a scheduled task.
Task handles allow checking the status of a spawned fiber and optionally cancelling it before completion.
A cooperative fiber scheduler with event loop integration.
The FiberScheduler manages a collection of fibers (tasks) and executes them cooperatively. When a fiber yields, the scheduler picks the next ready fiber to run. The scheduler can optionally integrate with an EventLoop to handle I/O-bound fibers efficiently.
Example:
auto scheduler = new FiberScheduler();
scheduler.spawn({
writeln("Task 1: Step 1");
Fiber.yield();
writeln("Task 1: Step 2");
});
scheduler.spawn({
writeln("Task 2: Running");
});
scheduler.run();
// Output:
// Task 1: Step 1
// Task 2: Running
// Task 1: Step 2ScheduledTask[] tasks_size_t[] readyQueue_size_t nextId_bool running_size_t currentTaskId_size_t completedCount_TaskHandle spawn(void delegate() fn, string name = null) @trustedSpawn a new fiber task with the given delegate.size_t taskCount() @property const pure @safe nothrow @nogcGet the number of tasks currently managed by the scheduler.size_t readyCount() @property const pure @safe nothrow @nogcGet the number of tasks in the ready queue.bool isRunning() @property const pure @safe nothrow @nogcCheck if the scheduler is currently running.size_t currentTask() @property const pure @safe nothrow @nogcGet the ID of the currently executing task.