From 2a60575d92176a8778186077c5c704a1c6381519 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Tue, 28 Jun 2022 09:36:58 +0300 Subject: Initial RandomFuture --- src/main.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src') 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 { Pending, } +pub struct RandomFuture {} + +impl SimpleFuture for RandomFuture { + type Output = f64; + fn poll(&mut self, _wake: fn()) -> Poll { + 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() { -- cgit v1.3.1