9 releases

0.2.0 Jan 19, 2020
0.1.4 Oct 28, 2018
0.1.3 Aug 5, 2018
0.1.2 Jan 8, 2017
0.0.1 Apr 20, 2015

#73 in Concurrency

Download history 81249/week @ 2024-07-24 80699/week @ 2024-07-31 83629/week @ 2024-08-07 80706/week @ 2024-08-14 84920/week @ 2024-08-21 77391/week @ 2024-08-28 85851/week @ 2024-09-04 78656/week @ 2024-09-11 78582/week @ 2024-09-18 82170/week @ 2024-09-25 88793/week @ 2024-10-02 82850/week @ 2024-10-09 84434/week @ 2024-10-16 86673/week @ 2024-10-23 86419/week @ 2024-10-30 84350/week @ 2024-11-06

357,171 downloads per month
Used in 2,542 crates (27 directly)

MIT license

44KB
786 lines

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");

No runtime deps