Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 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. drop(x);
  16. await!(do_nothing());
  17.  
  18. }
  19.  
  20. fn main() {
  21. let runtime = Runtime::new().unwrap();
  22. let executor = runtime.executor();
  23. let x = Arc::new(Mutex::new(0));
  24. executor.spawn(foo(x.clone()));
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement