Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #![feature(await_macro, async_await, futures_api)]
  2.  
  3. use std::future::Future;
  4. use std::sync::Mutex;
  5. use std::sync::Arc;
  6. use tokio::{runtime::Runtime};
  7.  
  8. async fn do_nothing() {
  9.  
  10. }
  11.  
  12. async fn foo(count: Arc<Mutex<u32>>) {
  13. let mut x = count.lock().unwrap();
  14. *x += 1;
  15. await!(do_nothing());
  16.  
  17. }
  18.  
  19. fn main() {
  20. let runtime = Runtime::new().unwrap();
  21. let executor = runtime.executor();
  22. let x = Arc::new(Mutex::new(0));
  23. executor.spawn(foo(x.clone()));
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement