File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 1
1
# Changes
2
2
3
3
## Unreleased - 2021-xx-xx
4
+ * Add ` Arbiter::handle ` to get a handle of an owned Arbiter. [ #274 ]
5
+
6
+ [ #274 ] : https://github.com/actix/actix-net/pull/274
4
7
5
8
6
9
## 2.0.1 - 2021-02-06
Original file line number Diff line number Diff line change @@ -172,13 +172,18 @@ impl Arbiter {
172
172
hnd
173
173
}
174
174
175
+ /// Return a handle to the this Arbiter's message sender.
176
+ pub fn handle ( & self ) -> ArbiterHandle {
177
+ ArbiterHandle :: new ( self . tx . clone ( ) )
178
+ }
179
+
175
180
/// Return a handle to the current thread's Arbiter's message sender.
176
181
///
177
182
/// # Panics
178
183
/// Panics if no Arbiter is running on the current thread.
179
184
pub fn current ( ) -> ArbiterHandle {
180
185
HANDLE . with ( |cell| match * cell. borrow ( ) {
181
- Some ( ref addr ) => addr . clone ( ) ,
186
+ Some ( ref hnd ) => hnd . clone ( ) ,
182
187
None => panic ! ( "Arbiter is not running." ) ,
183
188
} )
184
189
}
Original file line number Diff line number Diff line change @@ -122,6 +122,28 @@ fn arbiter_spawn_fn_runs() {
122
122
arbiter. join ( ) . unwrap ( ) ;
123
123
}
124
124
125
+ #[ test]
126
+ fn arbiter_handle_spawn_fn_runs ( ) {
127
+ let sys = System :: new ( ) ;
128
+
129
+ let ( tx, rx) = channel :: < u32 > ( ) ;
130
+
131
+ let arbiter = Arbiter :: new ( ) ;
132
+ let handle = arbiter. handle ( ) ;
133
+ drop ( arbiter) ;
134
+
135
+ handle. spawn_fn ( move || {
136
+ tx. send ( 42 ) . unwrap ( ) ;
137
+ System :: current ( ) . stop ( )
138
+ } ) ;
139
+
140
+ let num = rx. recv_timeout ( Duration :: from_secs ( 2 ) ) . unwrap ( ) ;
141
+ assert_eq ! ( num, 42 ) ;
142
+
143
+ handle. stop ( ) ;
144
+ sys. run ( ) . unwrap ( ) ;
145
+ }
146
+
125
147
#[ test]
126
148
fn arbiter_drop_no_panic_fn ( ) {
127
149
let _ = System :: new ( ) ;
You can’t perform that action at this time.
0 commit comments