Skip to content

Tokio test spawn local #8

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

Closed
wants to merge 9 commits into from
Closed
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
11 changes: 9 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ pin-project = "1"
# For timer only
# TODO, Add this under a feature gate
# TODO, Only tokio::sync::watch channel is used (find individual dependency)
tokio = { version = "1.0", default-features = false, features = ["sync"] }
# tokio = { version = "=1.38.1", default-features = false, features = ["sync"] }
tokio = { git = "https://github.com/tokio-rs/tokio", rev = "ab53bf0c4727ae63c6a3a3d772b7bd837d2f49c3", default-features = false, features = [
"sync",
] }

[dev-dependencies]
tokio = { version = "1", features = ["full"] }
# tokio = { version = "=1.38.1", features = ["full"] }
tokio = { git = "https://github.com/tokio-rs/tokio", rev = "ab53bf0c4727ae63c6a3a3d772b7bd837d2f49c3", features = [
"full",
] }
futures = "0.3"
82 changes: 82 additions & 0 deletions tests/futures_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
use futures::StreamExt;
use ticked_async_executor::TickedAsyncExecutor;

const DELTA: f64 = 1000.0 / 60.0;

// #[test]
// fn test_futures_join() {
// let executor = TickedAsyncExecutor::default();

// let (mut tx1, mut rx1) = futures::channel::mpsc::channel::<usize>(1);
// let (mut tx2, mut rx2) = futures::channel::mpsc::channel::<usize>(1);
// executor
// .spawn_local("ThreadedFuture", async move {
// let (a, b) = futures::join!(rx1.next(), rx2.next());
// assert_eq!(a.unwrap(), 10);
// assert_eq!(b.unwrap(), 20);
// })
// .detach();

// let (mut tx3, mut rx3) = futures::channel::mpsc::channel::<usize>(1);
// let (mut tx4, mut rx4) = futures::channel::mpsc::channel::<usize>(1);
// executor
// .spawn_local("LocalFuture", async move {
// let (a, b) = futures::join!(rx3.next(), rx4.next());
// assert_eq!(a.unwrap(), 10);
// assert_eq!(b.unwrap(), 20);
// })
// .detach();

// tx1.try_send(10).unwrap();
// tx3.try_send(10).unwrap();
// for _ in 0..10 {
// executor.tick(DELTA);
// }
// tx2.try_send(20).unwrap();
// tx4.try_send(20).unwrap();

// while executor.num_tasks() != 0 {
// executor.tick(DELTA);
// }
// }

// #[test]
// fn test_futures_select() {
// let executor = TickedAsyncExecutor::default();

// let (mut tx1, mut rx1) = futures::channel::mpsc::channel::<usize>(1);
// let (_tx2, mut rx2) = futures::channel::mpsc::channel::<usize>(1);
// executor
// .spawn_local("ThreadedFuture", async move {
// futures::select! {
// data = rx1.next() => {
// assert_eq!(data.unwrap(), 10);
// }
// _ = rx2.next() => {}
// }
// })
// .detach();

// let (mut tx3, mut rx3) = futures::channel::mpsc::channel::<usize>(1);
// let (_tx4, mut rx4) = futures::channel::mpsc::channel::<usize>(1);
// executor
// .spawn_local("LocalFuture", async move {
// futures::select! {
// data = rx3.next() => {
// assert_eq!(data.unwrap(), 10);
// }
// _ = rx4.next() => {}
// }
// })
// .detach();

// for _ in 0..10 {
// executor.tick(DELTA);
// }

// tx1.try_send(10).unwrap();
// tx3.try_send(10).unwrap();
// while executor.num_tasks() != 0 {
// executor.tick(DELTA);
// }
// }
8 changes: 4 additions & 4 deletions tests/tokio_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn test_tokio_join() {
let (tx1, mut rx1) = tokio::sync::mpsc::channel::<usize>(1);
let (tx2, mut rx2) = tokio::sync::mpsc::channel::<usize>(1);
executor
.spawn("ThreadedFuture", async move {
.spawn_local("ThreadedFuture", async move {
let (a, b) = tokio::join!(rx1.recv(), rx2.recv());
assert_eq!(a.unwrap(), 10);
assert_eq!(b.unwrap(), 20);
Expand All @@ -19,7 +19,7 @@ fn test_tokio_join() {
let (tx3, mut rx3) = tokio::sync::mpsc::channel::<usize>(1);
let (tx4, mut rx4) = tokio::sync::mpsc::channel::<usize>(1);
executor
.spawn("LocalFuture", async move {
.spawn_local("LocalFuture", async move {
let (a, b) = tokio::join!(rx3.recv(), rx4.recv());
assert_eq!(a.unwrap(), 10);
assert_eq!(b.unwrap(), 20);
Expand All @@ -46,7 +46,7 @@ fn test_tokio_select() {
let (tx1, mut rx1) = tokio::sync::mpsc::channel::<usize>(1);
let (_tx2, mut rx2) = tokio::sync::mpsc::channel::<usize>(1);
executor
.spawn("ThreadedFuture", async move {
.spawn_local("ThreadedFuture", async move {
tokio::select! {
data = rx1.recv() => {
assert_eq!(data.unwrap(), 10);
Expand All @@ -59,7 +59,7 @@ fn test_tokio_select() {
let (tx3, mut rx3) = tokio::sync::mpsc::channel::<usize>(1);
let (_tx4, mut rx4) = tokio::sync::mpsc::channel::<usize>(1);
executor
.spawn("LocalFuture", async move {
.spawn_local("LocalFuture", async move {
tokio::select! {
data = rx3.recv() => {
assert_eq!(data.unwrap(), 10);
Expand Down
Loading