scheduled_executor/
lib.rs

1//! ## The library
2//!
3//! This library provides a series of utilities for scheduling and executing tasks (functions and
4//! closures). Tasks can be executed at fixed interval or at fixed rates, and can be executed
5//! sequentially in the main executor thread or in parallel using a thread pool.
6//!
7//! ### Executors
8//!
9//! - [`CoreExecutor`]: schedule and execute tasks on a single thread, ideal for short running tasks.
10//! - [`ThreadPoolExecutor`]: schedule and execute tasks on a thread pool. Can be used for long
11//! running tasks.
12//!
13//! [`CoreExecutor`]: https://fede1024.github.io/rust-scheduled-executor/scheduled_executor/executor/struct.CoreExecutor.html
14//! [`ThreadPoolExecutor`]: https://fede1024.github.io/rust-scheduled-executor/scheduled_executor/executor/struct.ThreadPoolExecutor.html
15//!
16//! ### Task group
17//! The scheduled-executor crate also provides an abstraction for the execution of groups of tasks
18//! called [`TaskGroup`]. A `TaskGroup` requires a method for the generation of the collection of
19//! tasks, which will be executed at the beginning of each cycle, and a method for the execution of
20//! individual task, which will be executed for each task.
21//!
22//! To see a task group in action, check out the [`task_group.rs`] example.
23//!
24//! [`TaskGroup`]: https://fede1024.github.io/rust-scheduled-executor/scheduled_executor/task_group/trait.TaskGroup.html
25//! [`task_group.rs`]: https://github.com/fede1024/rust-scheduled-executor/blob/master/examples/task_group.rs
26//!
27//! ### Documentation
28//!
29//! - [Current master branch](https://fede1024.github.io/rust-scheduled-executor/)
30//! - [Latest release](https://docs.rs/scheduled-executor/)
31//!
32//! ### Examples
33//!
34//! Scheduling periodic task is very simple. Here is an example using a thread pool:
35//!
36//! ```rust,ignore
37//! // Starts a new thread-pool based executor with 4 threads
38//! let executor = ThreadPoolExecutor::new(4)?;
39//!
40//! executor.schedule_fixed_rate(
41//!     Duration::from_secs(2),  // Wait 2 seconds before scheduling the first task
42//!     Duration::from_secs(5),  // and schedule every following task at 5 seconds intervals
43//!     |remote| {
44//!         // Code to be scheduled. The code will run on one of the threads in the thread pool.
45//!         // The `remote` handle can be used to schedule additional work on the event loop,
46//!         // if needed.
47//!     },
48//! );
49//! ```
50//!
51#[macro_use] extern crate log;
52extern crate futures;
53extern crate tokio_core;
54extern crate futures_cpupool;
55
56pub mod executor;
57pub mod task_group;
58
59pub use executor::{CoreExecutor, ThreadPoolExecutor};
60pub use task_group::{TaskGroup, TaskGroupScheduler};