#shuttle #future #synchronization

futures-shuttle

Futures-aware shuttle synchronization object

5 releases

Uses old Rust 2015

0.2.1 Apr 7, 2018
0.2.0 Mar 26, 2018
0.1.2 Mar 21, 2018
0.1.1 Mar 19, 2018
0.1.0 Mar 14, 2018

#1549 in Asynchronous

22 downloads per month

MIT/Apache

14KB
312 lines

futures-shuttle

Build status

Futures-aware shuttle synchronization object

Creates a new shuttle synchronization object for sharing values between two asynchronous tasks. Each half can be separately owned and sent across tasks.

Examples

extern crate futures;
extern crate futures_shuttle;

use std::thread;

use futures_shuttle::shuttle;
use futures::*;

fn main() {
    let (mut left, mut right) = shuttle(42);

    assert!(left.is_mine());
    assert!(!right.is_mine());
    assert_eq!(left.get(), 42);
    left.set(84);
    left.send();
    assert!(!left.is_mine());
    assert!(right.is_mine());
    assert_eq!(right.get(), 84);
}

lib.rs:

Futures-based Shuttle

A channel for shuttling a single object/message back and forth between two asynchronous tasks. Contrary to the mutex or lock, shuttle always belongs to one of the two tasks. The side that owns the control over Shuttle at a specific moment can manipulate its content and send it to the other side. At this point control goes over to the other side and the original side loses the ability to access the Shuttle object. It, however, can wait for Shuttle to come back from the other side of the track, and then regain the access.

Dependencies

~1MB
~18K SLoC