1313 issue = "50547" ) ]
1414
1515use fmt;
16- use super :: { Executor , Waker , LocalWaker } ;
16+ use super :: { Spawn , Waker , LocalWaker } ;
1717
1818/// Information about the currently-running task.
1919///
2020/// Contexts are always tied to the stack, since they are set up specifically
2121/// when performing a single `poll` step on a task.
2222pub struct Context < ' a > {
2323 local_waker : & ' a LocalWaker ,
24- executor : & ' a mut dyn Executor ,
24+ spawner : & ' a mut dyn Spawn ,
2525}
2626
2727impl < ' a > fmt:: Debug for Context < ' a > {
@@ -32,13 +32,14 @@ impl<'a> fmt::Debug for Context<'a> {
3232}
3333
3434impl < ' a > Context < ' a > {
35- /// Create a new task `Context` with the provided `local_waker`, `waker`, and `executor`.
35+ /// Create a new task `Context` with the provided `local_waker`, `waker`,
36+ /// and `spawner`.
3637 #[ inline]
37- pub fn new ( local_waker : & ' a LocalWaker , executor : & ' a mut dyn Executor ) -> Context < ' a > {
38- Context {
39- local_waker ,
40- executor ,
41- }
38+ pub fn new (
39+ local_waker : & ' a LocalWaker ,
40+ spawner : & ' a mut dyn Spawn ,
41+ ) -> Context < ' a > {
42+ Context { local_waker , spawner }
4243 }
4344
4445 /// Get the `LocalWaker` associated with the current task.
@@ -53,40 +54,45 @@ impl<'a> Context<'a> {
5354 unsafe { & * ( self . local_waker as * const LocalWaker as * const Waker ) }
5455 }
5556
56- /// Get the default executor associated with this task.
57+ /// Get the spawner associated with this task.
5758 ///
5859 /// This method is useful primarily if you want to explicitly handle
5960 /// spawn failures.
6061 #[ inline]
61- pub fn executor ( & mut self ) -> & mut dyn Executor {
62- self . executor
62+ pub fn spawner ( & mut self ) -> & mut dyn Spawn {
63+ self . spawner
6364 }
6465
65- /// Produce a context like the current one, but using the given waker instead.
66+ /// Produce a context like the current one, but using the given waker
67+ /// instead.
6668 ///
6769 /// This advanced method is primarily used when building "internal
6870 /// schedulers" within a task, where you want to provide some customized
6971 /// wakeup logic.
7072 #[ inline]
71- pub fn with_waker < ' b > ( & ' b mut self , local_waker : & ' b LocalWaker ) -> Context < ' b > {
73+ pub fn with_waker < ' b > (
74+ & ' b mut self ,
75+ local_waker : & ' b LocalWaker ,
76+ ) -> Context < ' b > {
7277 Context {
7378 local_waker,
74- executor : self . executor ,
79+ spawner : self . spawner ,
7580 }
7681 }
7782
78- /// Produce a context like the current one, but using the given executor
83+ /// Produce a context like the current one, but using the given spawner
7984 /// instead.
8085 ///
8186 /// This advanced method is primarily used when building "internal
8287 /// schedulers" within a task.
8388 #[ inline]
84- pub fn with_executor < ' b , E > ( & ' b mut self , executor : & ' b mut E ) -> Context < ' b >
85- where E : Executor
86- {
89+ pub fn with_spawner < ' b , Sp : Spawn > (
90+ & ' b mut self ,
91+ spawner : & ' b mut Sp ,
92+ ) -> Context < ' b > {
8793 Context {
8894 local_waker : self . local_waker ,
89- executor ,
95+ spawner ,
9096 }
9197 }
9298}
0 commit comments