11use std:: error:: Error ;
2- use std:: fmt;
3- use std:: io;
2+ use std:: { fmt, io} ;
43
5- use futures:: { future, Future } ;
6- use tokio_current_thread:: Handle as ExecutorHandle ;
4+ use futures:: Future ;
75use tokio_current_thread:: { self as current_thread, CurrentThread } ;
86use tokio_executor;
97use tokio_reactor:: { self , Reactor } ;
@@ -26,58 +24,6 @@ pub struct Runtime {
2624 executor : CurrentThread < Timer < Reactor > > ,
2725}
2826
29- /// Handle to spawn a future on the corresponding `CurrentThread` runtime instance
30- #[ derive( Debug , Clone ) ]
31- pub struct Handle ( ExecutorHandle ) ;
32-
33- impl Handle {
34- /// Spawn a future onto the `CurrentThread` runtime instance corresponding to this handle
35- ///
36- /// # Panics
37- ///
38- /// This function panics if the spawn fails. Failure occurs if the `CurrentThread`
39- /// instance of the `Handle` does not exist anymore.
40- pub fn spawn < F > ( & self , future : F ) -> Result < ( ) , tokio_executor:: SpawnError >
41- where
42- F : Future < Item = ( ) , Error = ( ) > + Send + ' static ,
43- {
44- self . 0 . spawn ( future)
45- }
46-
47- /// Provides a best effort **hint** to whether or not `spawn` will succeed.
48- ///
49- /// This function may return both false positives **and** false negatives.
50- /// If `status` returns `Ok`, then a call to `spawn` will *probably*
51- /// succeed, but may fail. If `status` returns `Err`, a call to `spawn` will
52- /// *probably* fail, but may succeed.
53- ///
54- /// This allows a caller to avoid creating the task if the call to `spawn`
55- /// has a high likelihood of failing.
56- pub fn status ( & self ) -> Result < ( ) , tokio_executor:: SpawnError > {
57- self . 0 . status ( )
58- }
59- }
60-
61- impl < T > future:: Executor < T > for Handle
62- where
63- T : Future < Item = ( ) , Error = ( ) > + Send + ' static ,
64- {
65- fn execute ( & self , future : T ) -> Result < ( ) , future:: ExecuteError < T > > {
66- if let Err ( e) = self . status ( ) {
67- let kind = if e. is_at_capacity ( ) {
68- future:: ExecuteErrorKind :: NoCapacity
69- } else {
70- future:: ExecuteErrorKind :: Shutdown
71- } ;
72-
73- return Err ( future:: ExecuteError :: new ( kind, future) ) ;
74- }
75-
76- let _ = self . spawn ( future) ;
77- Ok ( ( ) )
78- }
79- }
80-
8127/// Error returned by the `run` function.
8228#[ derive( Debug ) ]
8329pub struct RunError {
@@ -120,14 +66,6 @@ impl Runtime {
12066 }
12167 }
12268
123- /// Get a new handle to spawn futures on the single-threaded Tokio runtime
124- ///
125- /// Different to the runtime itself, the handle can be sent to different
126- /// threads.
127- pub fn handle ( & self ) -> Handle {
128- Handle ( self . executor . handle ( ) . clone ( ) )
129- }
130-
13169 /// Spawn a future onto the single-threaded Tokio runtime.
13270 ///
13371 /// See [module level][mod] documentation for more details.
0 commit comments