sealrs/executors/
mod.rs

1//! Executors environment
2//!
3//! # Table of Contents
4//! 1. [Introduction](#introduction)
5//! 2. [ThreadPinnedExecutor](#threadpinnedexecutor)
6//!
7//! # Introduction
8//!
9//! In modern asynchronous frameworks, executors is a second level of architecture after threads of
10//! operation system. This objects allows pass some task to them and start to do some other work,
11//! right after that. How and when this work will be really executed, defined by an executor
12//! implementation. This async primitive is a basic on which developed primitives of next
13//! architecture level - actors and promises. Actors uses executors as basis for message dispatching
14//! system. Promises uses they as internal runtime environment.
15//!
16//! Technically executor is a trait with the single abstract method:
17//!
18//! ```
19//! fn execute(&mut self, f: ExecutorTask, options: Option<Box<Any>>);
20//! ```
21//!
22//! Besides on this, actors and futures is fully indifferent about how executors work internal, and
23//! they know nothing about this. They see only the 'execute' method with hidden realization. This
24//! fact allows to create any type of executors and slip it them without any impacts to code of the
25//! original module. You may to use executors from predefined set or you may implement your own
26//! version based on the 'Executor' trait. For now, in the library exists few predefined versions
27//! of executors.
28//!
29//! # ThreadPinnedExecutor
30//!
31//! This executor creates thread pool with specified counts of threads. Each thread has it's own
32//! queue. When you pass task to the executor, you may explicitly specify thread id on which
33//! this task will be executed. If thread id does not specified explicitly, it will be selected
34//! automatically bases on the task distribution strategy. You may use this executor type by follow:
35//!
36//! ```
37//! let mut executor = ThreadPinnedExecutor::new()
38//!     .set_threads_count(8)
39//!     .set_distribution_strategy(DistributionStrategy::Load)
40//!     .run();
41//!
42//! let f0 = Box::new( || { println!("Task on implicitly selected thread") });
43//! executor.execute(f0, None);
44//!
45//! let f1 = Box::new( || { println!("Task on explicitly selected thread with id 6") });
46//! executor.execute(f1, Some( Box::new(TaskOptions { thread_id: Some(6) } )));
47//! ```
48
49pub mod executor;
50pub mod thread_pinned_executor;