diff options
| author | Tomás Vallotton <tvallotton@uc.cl> | 2023-12-06 14:09:16 -0300 | 
|---|---|---|
| committer | Tomás Vallotton <tvallotton@uc.cl> | 2024-01-20 10:14:21 -0300 | 
| commit | 403718b19de6ad0979833fd2cf6074f2a1b50c8c (patch) | |
| tree | d20ae312ed4e866e4dfd84d486197b2ed6cbaaa6 /library/alloc/src/task.rs | |
| parent | 232cc2b4e4ba0a3c0e5e45fed64f0783201805f8 (diff) | |
| download | rust-403718b19de6ad0979833fd2cf6074f2a1b50c8c.tar.gz rust-403718b19de6ad0979833fd2cf6074f2a1b50c8c.zip | |
feat: add try_waker and From<&mut Context> for ContextBuilder to allow the extention of contexts by futures
Diffstat (limited to 'library/alloc/src/task.rs')
| -rw-r--r-- | library/alloc/src/task.rs | 20 | 
1 files changed, 11 insertions, 9 deletions
| diff --git a/library/alloc/src/task.rs b/library/alloc/src/task.rs index 16ae5241da8..736a55700f6 100644 --- a/library/alloc/src/task.rs +++ b/library/alloc/src/task.rs @@ -165,16 +165,15 @@ fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker { /// # Examples /// -/// A -/// /// This is a simplified example of a `spawn` and a `block_on` function. The `spawn` function /// is used to push new tasks onto the run queue, while the block on function will remove them /// and poll them. When a task is woken, it will put itself back on the run queue to be polled by the executor. /// /// **Note:** A real world example would interlieve poll calls with calls to an io reactor to wait for events instead -/// of spinning on a loop. +/// of spinning on a loop. /// /// ```rust +/// #![feature(local_waker)] /// use std::task::{LocalWake, ContextBuilder, LocalWaker}; /// use std::future::Future; /// use std::pin::Pin; @@ -204,9 +203,9 @@ fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker { /// where /// F: Future<Output=()> + 'static + Send + Sync /// { -/// let task = Rc::new(Box::pin(future)); +/// let task = RefCell::new(Box::pin(future)); /// RUN_QUEUE.with_borrow_mut(|queue| { -/// queue.push_back(task) +/// queue.push_back(Rc::new(Task(task))); /// }); /// } /// @@ -221,19 +220,22 @@ fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker { /// return; /// }; /// // cast the Rc<Task> into a `LocalWaker` -/// let waker: LocalWaker = task.into(); +/// let waker: LocalWaker = task.clone().into(); /// // Build the context using `ContextBuilder` -/// let mut cx = ContextBuilder::new() -/// .local_waker(&waker) +/// let mut cx = ContextBuilder::from_local_waker(&waker) /// .build(); /// /// // Poll the task -/// task.0 +/// let _ = task.0 /// .borrow_mut() /// .as_mut() /// .poll(&mut cx); /// } /// } +/// +/// block_on(async { +/// println!("hello world"); +/// }); /// ``` /// #[unstable(feature = "local_waker", issue = "none")] | 
