This repository was archived by the owner on Oct 30, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +41
-1
lines changed Expand file tree Collapse file tree 1 file changed +41
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
use std:: pin:: Pin ;
4
4
5
+ use futures:: future:: FutureObj ;
5
6
use futures:: prelude:: * ;
6
- use futures:: task:: { Context , Poll } ;
7
+ use futures:: task:: { Context , Poll , Spawn , SpawnError } ;
8
+
9
+ /// A [`Spawn`] handle to runtime's thread pool for spawning futures.
10
+ ///
11
+ /// This allows integrating runtime with libraries based on explicitly passed spawners.
12
+ #[ derive( Debug ) ]
13
+ pub struct Spawner {
14
+ _reserved : ( ) ,
15
+ }
16
+
17
+ impl Spawner {
18
+ /// Construct a new [`Spawn`] handle.
19
+ pub fn new ( ) -> Self {
20
+ Self { _reserved : ( ) }
21
+ }
22
+ }
23
+
24
+ impl Default for Spawner {
25
+ fn default ( ) -> Self {
26
+ Self :: new ( )
27
+ }
28
+ }
29
+
30
+ impl Clone for Spawner {
31
+ fn clone ( & self ) -> Self {
32
+ Self :: new ( )
33
+ }
34
+ }
35
+
36
+ impl Spawn for Spawner {
37
+ fn spawn_obj ( & mut self , future : FutureObj < ' static , ( ) > ) -> Result < ( ) , SpawnError > {
38
+ ( & * self ) . spawn_obj ( future)
39
+ }
40
+ }
41
+
42
+ impl < ' a > Spawn for & ' a Spawner {
43
+ fn spawn_obj ( & mut self , future : FutureObj < ' static , ( ) > ) -> Result < ( ) , SpawnError > {
44
+ runtime_raw:: current_runtime ( ) . spawn_boxed ( future. boxed ( ) )
45
+ }
46
+ }
7
47
8
48
/// Spawn a future on the runtime's thread pool.
9
49
///
You can’t perform that action at this time.
0 commit comments