summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 8d6c6cb2e2fd3f2c106db70e1ba303e5b8fcf3de (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
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();
        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);
}