[−][src]Module desync::scheduler
The scheduler provides the JobQueue
synchronisation mechanism.
Scheduler
The scheduler provides a new synchronisation mechanism: the JobQueue
. You can get one
by calling scheduler::queue()
:
use desync::scheduler; let queue = scheduler::queue();
A JobQueue
allows jobs to be scheduled in the background. Jobs are scheduled in the order
that they arrive, so anything on a queue is run synchronously with respect to the queue
itself. The desync
call can be used to schedule work:
scheduler::desync(&queue, || println!("First job")); scheduler::desync(&queue, || println!("Second job")); scheduler::desync(&queue, || println!("Third job"));
These will be scheduled onto background threads created by the scheduler. There is also a
sync
method. Unlike desync
, this can return a value from the job function it takes
as a parameter and doesn't return until its job has completed:
scheduler::desync(&queue, || println!("In the background")); let someval = scheduler::sync(&queue, || { println!("In the foreground"); 42 });
As queues are synchronous with themselves, it's possible to access data without needing
extra synchronisation primitives: desync
is perfect for updating data in the background
and sync
can be used to perform operations where data is returned to the calling thread.
Structs
JobQueue | A job queue provides a list of jobs to perform in order |
Scheduler | The scheduler is used to schedule tasks onto a pool of threads |
Functions
async | Deprecated Performs an action asynchronously on the specified queue |
desync | Performs an action asynchronously on the specified queue |
future | Schedules a job to run and returns a future for retrieving the result |
queue | Creates a scheduler queue |
scheduler | Retrieves the global scheduler |
sync | Performs an action synchronously on the specified queue |