Module desync::scheduler

source ·
Expand description

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

  • A job queue provides a list of jobs to perform in order
  • The queue resumer is used to resume a queue that was suspended using the suspend() function in the scheduler
  • The scheduler is used to schedule tasks onto a pool of threads
  • Future representing a task pending on a scheduler

Enums

  • Possible error conditions from a try_sync() call on the scheduler

Functions

  • asyncDeprecated
    Performs an action asynchronously on the specified queue
  • Performs an action asynchronously on the specified queue
  • Schedules a job to run asynchronously and returns a future for retrieving the result
  • Schedules a job to run and returns a future for retrieving the result
  • Creates a scheduler queue
  • Retrieves the global scheduler
  • Performs an action synchronously on the specified queue
  • Performs an action synchronously on the specified queue