Skip to content

Commit

Permalink
Try crossbeam
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmo0920 committed Sep 16, 2018
1 parent 847435c commit 9980c7f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ fluentd = []
readme-testing = ["skeptic"]
dev = ["clippy"]
time-as-integer = []
parallel-example = ["crossbeam"]

[build-dependencies.skeptic]
version = "~0.9"
Expand All @@ -32,6 +33,7 @@ rmp = "~0.8.0"
rmp-serde = "~0.13.0"
byteorder = "^1.0.0"
clippy = {version = '0.0.187', optional = true}
crossbeam = {version = "~0.4", optional = true}

[dev-dependencies]
failure = "~0.1.1"
Expand Down
29 changes: 29 additions & 0 deletions examples/crossbeam_thread.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
extern crate fruently;
#[cfg(feature = "crossbeam")]
extern crate crossbeam;

#[cfg(feature = "crossbeam")]
fn crossbeam_thread() {
use fruently::fluent::Fluent;
use std::collections::HashMap;
use fruently::forwardable::JsonForwardable;

let fruently = Fluent::new("127.0.0.1:24224", "test");
let mut obj: HashMap<String, String> = HashMap::new();
obj.insert("threaded".to_string(), "fruently".to_string());
let _threads: Vec<_> = (0..10)
.map(|_| {
let obj = obj.clone();
let fruently = fruently.clone();
crossbeam::scope(|scope| {
scope.spawn(|| { let _ = fruently.post(&obj); })
});
})
.collect();
}
#[cfg(not(feature = "crossbeam"))]
fn crossbeam_thread() {}

fn main() {
crossbeam_thread();
}

0 comments on commit 9980c7f

Please sign in to comment.