diff options
| author | Yuval Adam <_@yuv.al> | 2022-06-28 09:36:58 +0300 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2022-06-28 09:43:28 +0300 |
| commit | 2a60575d92176a8778186077c5c704a1c6381519 (patch) | |
| tree | e488ac1529dec3cacc81783ff27668a0d00096a3 /src | |
| parent | 7438c83aca7d5ba7eab7cafc3068207588c83ded (diff) | |
Initial RandomFuture
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs index e1e8efd..8d6c6cb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,10 +11,24 @@ enum Poll<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() { - let mut rng = rand::thread_rng(); - let y: f64 = rng.gen(); - println!("hello, world! {}", y); + println!("hello, world!"); } fn main() { |
