-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use edge_executor::{block_on, LocalExecutor}; | ||
|
||
fn main() { | ||
let local_ex: LocalExecutor = Default::default(); | ||
|
||
// Borrowed by `&mut` inside the future spawned on the executor | ||
let mut data = 3; | ||
|
||
let data = &mut data; | ||
|
||
let task = local_ex.spawn(async move { | ||
*data += 1; | ||
|
||
*data | ||
}); | ||
|
||
let res = block_on(local_ex.run(async { task.await * 2 })); | ||
|
||
assert_eq!(res, 8); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use async_channel::unbounded; | ||
use easy_parallel::Parallel; | ||
|
||
use edge_executor::{block_on, Executor}; | ||
|
||
fn main() { | ||
let ex: Executor = Default::default(); | ||
let (signal, shutdown) = unbounded::<()>(); | ||
|
||
Parallel::new() | ||
// Run four executor threads. | ||
.each(0..4, |_| block_on(ex.run(shutdown.recv()))) | ||
// Run the main future on the current thread. | ||
.finish(|| { | ||
block_on(async { | ||
println!("Hello world!"); | ||
drop(signal); | ||
}) | ||
}); | ||
} |