blob: 642901bf53527a9412ee4785eea6f41f85da2e94 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
use futures::executor::block_on;
use rand::prelude::*;
trait SimpleFuture {
type Output;
fn poll(&mut self, wake: fn()) -> Poll<Self::Output>;
}
enum Poll<T> {
Ready(T),
Pending,
}
pub struct RandomFuture {}
impl SimpleFuture for RandomFuture {
type Output = f64;
fn poll(&mut self, _wake: fn()) -> Poll<Self::Output> {
let mut rng = rand::thread_rng();
let y: f64 = rng.gen();
println!("y value {}", y);
if y > 0.9 {
Poll::Ready(y)
} else {
// probably need to utilize wake() here
Poll::Pending
}
}
}
async fn hello_world() {
println!("hello, world!");
}
fn main() {
let future = hello_world();
block_on(future);
}
|