13
13
issue = "50547" ) ]
14
14
15
15
use fmt;
16
- use super :: { Executor , Waker , LocalWaker } ;
16
+ use super :: { Spawn , Waker , LocalWaker } ;
17
17
18
18
/// Information about the currently-running task.
19
19
///
20
20
/// Contexts are always tied to the stack, since they are set up specifically
21
21
/// when performing a single `poll` step on a task.
22
22
pub struct Context < ' a > {
23
23
local_waker : & ' a LocalWaker ,
24
- executor : & ' a mut dyn Executor ,
24
+ spawner : & ' a mut dyn Spawn ,
25
25
}
26
26
27
27
impl < ' a > fmt:: Debug for Context < ' a > {
@@ -32,13 +32,14 @@ impl<'a> fmt::Debug for Context<'a> {
32
32
}
33
33
34
34
impl < ' 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`.
36
37
#[ 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 }
42
43
}
43
44
44
45
/// Get the `LocalWaker` associated with the current task.
@@ -53,40 +54,45 @@ impl<'a> Context<'a> {
53
54
unsafe { & * ( self . local_waker as * const LocalWaker as * const Waker ) }
54
55
}
55
56
56
- /// Get the default executor associated with this task.
57
+ /// Get the spawner associated with this task.
57
58
///
58
59
/// This method is useful primarily if you want to explicitly handle
59
60
/// spawn failures.
60
61
#[ 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
63
64
}
64
65
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.
66
68
///
67
69
/// This advanced method is primarily used when building "internal
68
70
/// schedulers" within a task, where you want to provide some customized
69
71
/// wakeup logic.
70
72
#[ 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 > {
72
77
Context {
73
78
local_waker,
74
- executor : self . executor ,
79
+ spawner : self . spawner ,
75
80
}
76
81
}
77
82
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
79
84
/// instead.
80
85
///
81
86
/// This advanced method is primarily used when building "internal
82
87
/// schedulers" within a task.
83
88
#[ 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 > {
87
93
Context {
88
94
local_waker : self . local_waker ,
89
- executor ,
95
+ spawner ,
90
96
}
91
97
}
92
98
}
0 commit comments