File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -488,6 +488,35 @@ impl<T> Task<T> {
488
488
}
489
489
}
490
490
491
+ impl Task < ( ) > {
492
+ /// Get a Spawner for the current multi-threaded executor.
493
+ ///
494
+ /// If called from an [`Executor`], get its Spawner.
495
+ ///
496
+ /// Otherwise, this method panics.
497
+ ///
498
+ /// # Examples
499
+ ///
500
+ /// ```
501
+ /// use async_executor::{Executor, Task};
502
+ ///
503
+ /// let ex = Executor::new();
504
+ ///
505
+ /// ex.run(async {
506
+ /// let spawner = Task::<_>::spawner();
507
+ /// let task = spawner.spawn(async { 1 + 2 });
508
+ /// assert_eq!(task.await, 3);
509
+ /// });
510
+ /// ```
511
+ pub fn spawner ( ) -> Spawner {
512
+ if EX . is_set ( ) {
513
+ EX . with ( |ex| ex. spawner ( ) )
514
+ } else {
515
+ panic ! ( "`Task::spawner()` must be called from an `Executor`" )
516
+ }
517
+ }
518
+ }
519
+
491
520
impl < T > Future for Task < T > {
492
521
type Output = T ;
493
522
You can’t perform that action at this time.
0 commit comments