FiberScheduler

An example Scheduler using Fibers.

This is an example scheduler that creates a new Fiber per call to spawn and multiplexes the execution of all fibers within the main thread.

Constructors

this
this(size_t max_parked_fibers)

Default ctor

Members

Classes

FiberBlocker
class FiberBlocker
Undocumented in source.
InfoFiber
class InfoFiber

Fiber which embeds neccessary info for FiberScheduler

Functions

create
void create(void delegate() op, bool insert_front)

Creates a new Fiber which calls the given delegate.

enterCriticalSection
void enterCriticalSection()

Disables Fiber switching

exitCriticalSection
void exitCriticalSection()

Enables Fiber switching

schedule
void schedule(void delegate() op)

Schedule a task to be run next time the scheduler yields

spawn
void spawn(void delegate() op)

This created a new Fiber for the supplied op and adds it to the dispatch list.

start
void start(void delegate() op)

This creates a new Fiber for the supplied op and then starts the dispatcher.

Interfaces

Resource
interface Resource

Resource type that will be tracked by FiberScheduler

Static functions

yield
void yield()

If the caller is a scheduled Fiber, this yields execution to another scheduled Fiber.

yieldAndThrow
void yieldAndThrow(Throwable t)

If the caller is a scheduled Fiber, this yields execution to another scheduled Fiber.

Examples

Ensure argument to start is run first

{
    scope sched = new FiberScheduler();
    bool startHasRun;
    sched.spawn(() => assert(startHasRun));
    sched.start(() { startHasRun = true; });
}
{
    scope sched = new FiberScheduler();
    bool startHasRun;
    sched.schedule(() => assert(startHasRun));
    sched.start(() { startHasRun = true; });
}

Meta