abrasion/third_party/cargo/vendor/dispatch-0.2.0
q3k 4a50bbf00d third_party/cargo: re-raze, fix winapi for windows 2021-05-03 23:43:36 +02:00
..
examples bump winit, vulkano, ... 2020-03-17 00:00:50 +01:00
src bump winit, vulkano, ... 2020-03-17 00:00:50 +01:00
.cargo-checksum.json bump winit, vulkano, ... 2020-03-17 00:00:50 +01:00
BUILD.bazel third_party/cargo: re-raze, fix winapi for windows 2021-05-03 23:43:36 +02:00
Cargo.lock bump winit, vulkano, ... 2020-03-17 00:00:50 +01:00
Cargo.toml bump winit, vulkano, ... 2020-03-17 00:00:50 +01:00
README.md bump winit, vulkano, ... 2020-03-17 00:00:50 +01:00

README.md

Rust wrapper for Apple's Grand Central Dispatch (GCD).

GCD is an implementation of task parallelism that allows tasks to be submitted to queues where they are scheduled to execute.

For more information, see Apple's Grand Central Dispatch reference.

Serial Queues

Serial queues execute tasks serially in FIFO order. The application's main queue is serial and can be accessed through the Queue::main function.

use dispatch::{Queue, QueueAttribute};

let queue = Queue::create("com.example.rust", QueueAttribute::Serial);
queue.async(|| println!("Hello"));
queue.async(|| println!("World"));

Concurrent Queues

Concurrent dispatch queues execute tasks concurrently. GCD provides global concurrent queues that can be accessed through the Queue::global function.

Queue has two methods that can simplify processing data in parallel, foreach and map:

use dispatch::{Queue, QueuePriority};

let queue = Queue::global(QueuePriority::Default);

let mut nums = vec![1, 2];
queue.foreach(&mut nums, |x| *x += 1);
assert!(nums == [2, 3]);

let nums = queue.map(nums, |x| x.to_string());
assert!(nums[0] == "2");