summaryrefslogtreecommitdiffstats
path: root/third_party/rust/tokio-threadpool/examples
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/tokio-threadpool/examples
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/tokio-threadpool/examples')
-rw-r--r--third_party/rust/tokio-threadpool/examples/depth.rs48
-rw-r--r--third_party/rust/tokio-threadpool/examples/hello.rs24
2 files changed, 72 insertions, 0 deletions
diff --git a/third_party/rust/tokio-threadpool/examples/depth.rs b/third_party/rust/tokio-threadpool/examples/depth.rs
new file mode 100644
index 0000000000..3d376dd38a
--- /dev/null
+++ b/third_party/rust/tokio-threadpool/examples/depth.rs
@@ -0,0 +1,48 @@
+extern crate env_logger;
+extern crate futures;
+extern crate tokio_threadpool;
+
+use futures::future::{self, Executor};
+use tokio_threadpool::*;
+
+use std::sync::mpsc;
+
+const ITER: usize = 2_000_000;
+// const ITER: usize = 30;
+
+fn chained_spawn() {
+ let pool = ThreadPool::new();
+ let tx = pool.sender().clone();
+
+ fn spawn(tx: Sender, res_tx: mpsc::Sender<()>, n: usize) {
+ if n == 0 {
+ res_tx.send(()).unwrap();
+ } else {
+ let tx2 = tx.clone();
+ tx.execute(future::lazy(move || {
+ spawn(tx2, res_tx, n - 1);
+ Ok(())
+ }))
+ .ok()
+ .unwrap();
+ }
+ }
+
+ loop {
+ println!("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
+ let (res_tx, res_rx) = mpsc::channel();
+
+ for _ in 0..10 {
+ spawn(tx.clone(), res_tx.clone(), ITER);
+ }
+
+ for _ in 0..10 {
+ res_rx.recv().unwrap();
+ }
+ }
+}
+
+pub fn main() {
+ let _ = ::env_logger::init();
+ chained_spawn();
+}
diff --git a/third_party/rust/tokio-threadpool/examples/hello.rs b/third_party/rust/tokio-threadpool/examples/hello.rs
new file mode 100644
index 0000000000..87eb688c2d
--- /dev/null
+++ b/third_party/rust/tokio-threadpool/examples/hello.rs
@@ -0,0 +1,24 @@
+extern crate env_logger;
+extern crate futures;
+extern crate tokio_threadpool;
+
+use futures::sync::oneshot;
+use futures::*;
+use tokio_threadpool::*;
+
+pub fn main() {
+ let _ = ::env_logger::init();
+
+ let pool = ThreadPool::new();
+ let tx = pool.sender().clone();
+
+ let res = oneshot::spawn(
+ future::lazy(|| {
+ println!("Running on the pool");
+ Ok::<_, ()>("complete")
+ }),
+ &tx,
+ );
+
+ println!("Result: {:?}", res.wait());
+}