File tree Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
## Unreleased - 2021-xx-xx
4
4
* Add ` Arbiter::handle ` to get a handle of an owned Arbiter. [ #274 ]
5
+ * Add ` System::try_current ` for situations where actix may or may not be running a System. [ #275 ]
5
6
6
7
[ #274 ] : https://github.com/actix/actix-net/pull/274
8
+ [ #275 ] : https://github.com/actix/actix-net/pull/275
7
9
8
10
9
11
## 2.0.1 - 2021-02-06
Original file line number Diff line number Diff line change @@ -100,6 +100,15 @@ impl System {
100
100
} )
101
101
}
102
102
103
+ /// Try to get current running system.
104
+ ///
105
+ /// Returns `None` if no System has been started.
106
+ ///
107
+ /// Contrary to `current`, this never panics.
108
+ pub fn try_current ( ) -> Option < System > {
109
+ CURRENT . with ( |cell| cell. borrow ( ) . clone ( ) )
110
+ }
111
+
103
112
/// Get handle to a the System's initial [Arbiter].
104
113
pub fn arbiter ( & self ) -> & ArbiterHandle {
105
114
& self . arbiter_handle
Original file line number Diff line number Diff line change @@ -288,3 +288,13 @@ fn new_arbiter_with_tokio() {
288
288
289
289
assert_eq ! ( false , counter. load( Ordering :: SeqCst ) ) ;
290
290
}
291
+
292
+ #[ test]
293
+ fn try_current_no_system ( ) {
294
+ assert ! ( System :: try_current( ) . is_none( ) )
295
+ }
296
+
297
+ #[ test]
298
+ fn try_current_with_system ( ) {
299
+ System :: new ( ) . block_on ( async { assert ! ( System :: try_current( ) . is_some( ) ) } ) ;
300
+ }
You can’t perform that action at this time.
0 commit comments