File tree Expand file tree Collapse file tree 2 files changed +20
-9
lines changed Expand file tree Collapse file tree 2 files changed +20
-9
lines changed Original file line number Diff line number Diff line change 11use Async ;
22use future:: Future ;
3- use executor;
3+ use executor:: { self , NotifyHandle } ;
44use task_impl:: ThreadNotify ;
55
66/// Provides thread-blocking operations on a future.
@@ -34,14 +34,12 @@ impl<T: Future> Blocking<T> {
3434 /// the inner future is not in a ready state.
3535 ///
3636 /// This function will return immediately if the inner future is not ready.
37- pub fn poll ( & mut self ) -> Option < Result < T :: Item , T :: Error > > {
38- ThreadNotify :: with_current ( |notify| {
39- match self . inner . poll_future_notify ( notify, 0 ) {
40- Ok ( Async :: NotReady ) => None ,
41- Ok ( Async :: Ready ( v) ) => Some ( Ok ( v) ) ,
42- Err ( e) => Some ( Err ( e) ) ,
43- }
44- } )
37+ pub fn try_take ( & mut self ) -> Option < Result < T :: Item , T :: Error > > {
38+ match self . inner . poll_future_notify ( & NotifyHandle :: noop ( ) , 0 ) {
39+ Ok ( Async :: NotReady ) => None ,
40+ Ok ( Async :: Ready ( v) ) => Some ( Ok ( v) ) ,
41+ Err ( e) => Some ( Err ( e) ) ,
42+ }
4543 }
4644
4745 /// Block the current thread until this future is resolved.
Original file line number Diff line number Diff line change @@ -615,6 +615,19 @@ impl NotifyHandle {
615615 NotifyHandle { inner : inner }
616616 }
617617
618+ /// Return a no-op notify handle
619+ pub fn noop ( ) -> NotifyHandle {
620+ struct Noop ;
621+
622+ impl Notify for Noop {
623+ fn notify ( & self , _id : usize ) { }
624+ }
625+
626+ const NOOP : & ' static Noop = & Noop ;
627+
628+ NotifyHandle :: from ( NOOP )
629+ }
630+
618631 /// Invokes the underlying instance of `Notify` with the provided `id`.
619632 pub fn notify ( & self , id : usize ) {
620633 unsafe { ( * self . inner ) . notify ( id) }
You can’t perform that action at this time.
0 commit comments