# HG changeset patch # User Shinji KONO # Date 1610970752 -32400 # Node ID 70ab6c2f7f6ee3235e03b1f25d9160cca0ca9ded # Parent 34aba7ec9efc089e6334dc5eae208c4add0ba178 fu_test worked. diff -r 34aba7ec9efc -r 70ab6c2f7f6e src/async_test/Cargo.toml --- a/src/async_test/Cargo.toml Mon Jan 18 15:53:03 2021 +0900 +++ b/src/async_test/Cargo.toml Mon Jan 18 20:52:32 2021 +0900 @@ -7,4 +7,6 @@ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -futures = "0.3" +futures = "0.3.12" +threadpool = "1.0" +rand = "0.5.5" \ No newline at end of file diff -r 34aba7ec9efc -r 70ab6c2f7f6e src/async_test/src/fu_test.rs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/async_test/src/fu_test.rs Mon Jan 18 20:52:32 2021 +0900 @@ -0,0 +1,44 @@ +use threadpool::ThreadPool; +use futures::executor::block_on; +use rand::Rng; + + +use std::{ + future::Future, + // pin::Pin, + // sync::{Arc, Mutex}, + // task::{Context, Poll}, + // thread, + // time::Duration, +}; +use futures::TryStreamExt; + +struct MyFuture ; + +impl MyFuture { + pub async fn call (&mut self) -> std::result::Result { + println!("poll called"); + let mut rng = rand::thread_rng(); + let i: i32 = rng.gen_range(0, 10); + if i < 5 { + Ok("success".to_string()) + } else { + Err("failure".to_string()) + } + } +} + +async fn get_future() -> Result<(), ()> { + (MyFuture{}).call().await.map(|res| { + println!("{}", res); + }).map_err(|err| { + println!("{}", err); + }) +} + +pub fn fu_test() { + + let future = get_future(); + // ThreadPool::new(4).execute(future); + block_on(future); +} \ No newline at end of file diff -r 34aba7ec9efc -r 70ab6c2f7f6e src/async_test/src/lib.rs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/async_test/src/lib.rs Mon Jan 18 20:52:32 2021 +0900 @@ -0,0 +1,2 @@ + +pub mod fu_test; \ No newline at end of file diff -r 34aba7ec9efc -r 70ab6c2f7f6e src/async_test/src/main.rs --- a/src/async_test/src/main.rs Mon Jan 18 15:53:03 2021 +0900 +++ b/src/async_test/src/main.rs Mon Jan 18 20:52:32 2021 +0900 @@ -38,4 +38,5 @@ let m = async_main(); println!("waiting"); block_on(m); + async_test::fu_test::fu_test(); } \ No newline at end of file diff -r 34aba7ec9efc -r 70ab6c2f7f6e src/t16thread/src/main.rs --- a/src/t16thread/src/main.rs Mon Jan 18 15:53:03 2021 +0900 +++ b/src/t16thread/src/main.rs Mon Jan 18 20:52:32 2021 +0900 @@ -29,8 +29,8 @@ } handle.join().unwrap(); // without this, some data are dropped main1(); - t16thread::mpsc_test::mainm(); - t16thread::mpsc_test::mainc(); - t16thread::racecondition::mainr(); + mainm(); + mainc(); + mainr(); t16thread::racecondition::mainu(); } \ No newline at end of file