#executor #scheduler

scheduled-executor

Single and multi-threaded task scheduler

4 releases (2 breaking)

Uses old Rust 2015

0.4.0 Nov 26, 2017
0.3.0 Jun 25, 2017
0.2.1 Jun 22, 2017
0.2.0 Jun 22, 2017

#17 in #scheduler

Download history 88/week @ 2021-01-11 75/week @ 2021-01-18 51/week @ 2021-01-25 37/week @ 2021-02-01 37/week @ 2021-02-08 43/week @ 2021-02-15 37/week @ 2021-02-22 38/week @ 2021-03-01 20/week @ 2021-03-08 37/week @ 2021-03-15 51/week @ 2021-03-22 48/week @ 2021-03-29 29/week @ 2021-04-05 33/week @ 2021-04-12 23/week @ 2021-04-19 47/week @ 2021-04-26

262 downloads per month

MIT license

33KB
595 lines

scheduled-executor

crates.io docs.rs Build Status

A simple function scheduler.

The library

This library provides a series of utilities for scheduling and executing tasks (functions and closures). Tasks can be executed at fixed interval or at fixed rates, and can be executed sequentially in the main executor thread or in parallel using a thread pool.

Executors

  • CoreExecutor: schedule and execute tasks on a single thread, ideal for short running tasks.
  • ThreadPoolExecutor: schedule and execute tasks on a thread pool. Can be used for long running tasks.

Task group

The scheduled-executor crate also provides an abstraction for the execution of groups of tasks called TaskGroup. A TaskGroup requires a method for the generation of the collection of tasks, which will be executed at the beginning of each cycle, and a method for the execution of individual task, which will be executed for each task.

To see a task group in action, check out the task_group.rs example.

Documentation

Examples

Scheduling periodic task is very simple. Here is an example using a thread pool:

// Starts a new thread-pool based executor with 4 threads
let executor = ThreadPoolExecutor::new(4)?;

executor.schedule_fixed_rate(
    Duration::from_secs(2),  // Wait 2 seconds before scheduling the first task
    Duration::from_secs(5),  // and schedule every following task at 5 seconds intervals
    |remote| {
        // Code to be scheduled. The code will run on one of the threads in the thread pool.
        // The `remote` handle can be used to schedule additional work on the event loop,
        // if needed.
    },
);

Dependencies

~4MB
~71K SLoC