7 releases

0.1.3 Aug 5, 2018
0.1.2 Jan 8, 2017
0.1.1 May 8, 2016
0.1.0 Apr 28, 2016
0.0.1 Apr 20, 2015

#12 in macOS APIs

Download history 13/week @ 2018-09-09 14/week @ 2018-09-16 19/week @ 2018-09-23 33/week @ 2018-09-30 19/week @ 2018-10-07 15/week @ 2018-10-14 92/week @ 2018-10-21 16/week @ 2018-10-28 63/week @ 2018-11-04 42/week @ 2018-11-11 76/week @ 2018-11-18 33/week @ 2018-11-25 44/week @ 2018-12-02

154 downloads per month
Used in 1 crate

MIT license

38KB
636 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