Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flume Overhaul #84

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,35 @@ exclude = [
]

[features]
select = []
async = ["futures-sink", "futures-core", "pin-project"]
eventual-fairness = ["async", "nanorand"]
default = ["async", "select", "eventual-fairness"]
default = ["std", "sync"]
# Support for `futures::Stream`
stream = []
# Support for `futures::Sink`
sink = ["futures-sink"]
# Standard library support (better thread contention performance)
std = []
# Synchronous channel operations like `.send(x)` and `.recv()`
sync = ["std", "pollster"]
# Synchronous timeout and deadline operations
time = ["sync", "futures-timer", "futures-util"]
# Support for the `select!` macro and selection
select = ["std", "futures-util/alloc"]

[dependencies]
spinning_top = "0.2"
futures-sink = { version = "0.3.5", default_features = false, optional = true }
futures-core = { version = "0.3.5", default_features = false, optional = true }
nanorand = { version = "0.5", features = ["getrandom"], optional = true }
pin-project = { version = "1", optional = true }
spin = { version = "0.7", default-features = false }
pin-project-lite = "0.2"
futures-core = "0.3"
futures-sink = { version = "0.3", optional = true }
futures-util = { version = "0.3", optional = true }
futures-timer = { version = "3.0", optional = true }
pollster = { version = "0.2", optional = true }
#futures-executor = "0.3"

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[dev-dependencies]
#flume-test = { path = "../flume-test" }
crossbeam-channel = "0.4"
crossbeam-utils = "0.7"
criterion = "0.3.1"
Expand Down
21 changes: 0 additions & 21 deletions examples/async.rs

This file was deleted.

30 changes: 0 additions & 30 deletions examples/perf.rs

This file was deleted.

37 changes: 24 additions & 13 deletions examples/select.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
#[cfg(feature = "select")]
use flume::Selector;

#[cfg(feature = "select")]
fn main() {
use flume::{Selector, unbounded};
use rand::prelude::*;

// Create two channels
let (red_tx, red_rx) = flume::unbounded();
let (blue_tx, blue_rx) = flume::unbounded();
let (red_tx, red_rx) = unbounded();
let (blue_tx, blue_rx) = unbounded();

// To make it fair, randomise the start order
let mut racers = vec![("Red", red_tx), ("Blue", blue_tx)];
racers.shuffle(&mut thread_rng());

for (color, tx) in racers {
std::thread::spawn(move || { let _ = tx.send(color); });
}

const RED: usize = 0;
const BLUE: usize = 1;

// Spawn two threads that each send a message into their respective channel
std::thread::spawn(move || { let _ = red_tx.send("Red"); });
std::thread::spawn(move || { let _ = blue_tx.send("Blue"); });
let mut sel = Selector::new();
let red = sel.recv(RED, &red_rx);
let blue = sel.recv(BLUE, &blue_rx);

// Race them to see which one sends their message first
let winner = Selector::new()
.recv(&red_rx, |msg| msg)
.recv(&blue_rx, |msg| msg)
.wait()
.unwrap();
let winner = match sel.wait() {
RED => red.get().unwrap(),
BLUE => blue.get().unwrap(),
_ => unreachable!(),
};

println!("{} won!", winner);
}
Expand Down
18 changes: 0 additions & 18 deletions examples/simple.rs

This file was deleted.

Loading