fn enter<S, F, R>(sleep: &mut S, f: F) -> R
    where F: FnOnce(&mut Context) -> R,
          S: Sleep<Wakeup = T>,
    {
        let mut runner = TaskRunner::new(sleep.wakeup());

        CURRENT.with(|current| {
            // Make sure that another task runner is not set.
            //
            // This should not be ever possible due to how `set_schedule`
            // is setup, but better safe than sorry!
            assert!(current.schedule.get().is_none());

            // Enter an execution scope
            let mut ctx = Context {
                cancel: &current.cancel,
            };

            // Set the scheduler to the TLS and perform setup work,
            // returning a future to execute.
            //
            // This could possibly suubmit other futures for execution.
            let ret = current.set_schedule(&mut runner.scheduler as &mut Schedule, || {
                f(&mut ctx)
            });

            // Execute the runner.
            //
            // This function will not return until either
            //
            // a) All futures have completed execution
            // b) `cancel_all_spawned` is called, forcing the executor to
            // return.
            runner.run(sleep, current);

            // Not technically required, but this makes the fact that `ctx`
            // needs to live until this point explicit.
            drop(ctx);

            ret
        })
    }
/// Enter a new `TaskRunner` context
///
/// This function handles advancing the scheduler state and blocking while
/// listening for notified futures.
///
/// First, a new task runner is created backed by the current
/// `sleep::BlockThread` handle. Passing `sleep::BlockThread` into the
/// scheduler is how scheduled futures unblock the thread, signalling that
/// there is more work to do.
///
/// Before any future is polled, the scheduler must be set to a thread-local
/// variable so that `execute` is able to submit new futures to the current
/// executor. Because `Scheduler::schedule` requires `&mut self`, this
/// introduces a mutability hazard. This hazard is minimized with some
/// indirection. See `set_schedule` for more details.
///
/// Once all context is setup, the init closure is invoked. This is the
/// "boostrapping" process that executes the initial futures into the
/// scheduler. After this, the function loops and advances the scheduler
/// state until all futures complete. When no scheduled futures are ready to
/// be advanced, the thread is blocked using `S: Sleep`.
Enter a new `TaskRunner` context
This function handles advancing the scheduler state and blocking while
listening for notified futures.

First, a new task runner is created backed by the current
`sleep::BlockThread` handle. Passing `sleep::BlockThread` into the
scheduler is how scheduled futures unblock the thread, signalling that
there is more work to do.

Before any future is polled, the scheduler must be set to a thread-local
variable so that `execute` is able to submit new futures to the current
executor. Because `Scheduler::schedule` requires `&mut self`, this
introduces a mutability hazard. This hazard is minimized with some
indirection. See `set_schedule` for more details.

Once all context is setup, the init closure is invoked. This is the
"boostrapping" process that executes the initial futures into the
scheduler. After this, the function loops and advances the scheduler
state until all futures complete. When no scheduled futures are ready to
be advanced, the thread is blocked using `S: Sleep`.
Enter a new ` TaskRunner ` context This function handles advancing the scheduler state and blocking while listening for notified futures . First a new task runner is created backed by the current ` sleep :: BlockThread ` handle . Passing ` sleep :: BlockThread ` into the scheduler is how scheduled futures unblock the thread signalling that there is more work to do . Before any future is polled the scheduler must be set to a thread - local variable so that ` execute ` is able to submit new futures to the current executor . Because ` Scheduler :: schedule ` requires ` &mut self ` this introduces a mutability hazard . This hazard is minimized with some indirection . See ` set_schedule ` for more details . Once all context is setup the init closure is invoked . This is the " boostrapping " process that executes the initial futures into the scheduler . After this the function loops and advances the scheduler state until all futures complete . When no scheduled futures are ready to be advanced the thread is blocked using ` S : Sleep ` .
fn enter<S, F, R>(sleep: &mut S, f: F) -> R
    where F: FnOnce(&mut Context) -> R,
          S: Sleep<Wakeup = T>,
    {
        let mut runner = TaskRunner::new(sleep.wakeup());
        CURRENT.with(|current| {
            // Make sure that another task runner is not set.
            //
            // This should not be ever possible due to how `set_schedule`
            // is setup, but better safe than sorry!
            assert!(current.schedule.get().is_none());
            // Enter an execution scope
            let mut ctx = Context {
                cancel: &current.cancel,
            };
            // Set the scheduler to the TLS and perform setup work,
            // returning a future to execute.
            //
            // This could possibly suubmit other futures for execution.
            let ret = current.set_schedule(&mut runner.scheduler as &mut Schedule, || {
                f(&mut ctx)
            });
            // Execute the runner.
            //
            // This function will not return until either
            //
            // a) All futures have completed execution
            // b) `cancel_all_spawned` is called, forcing the executor to
            // return.
            runner.run(sleep, current);
            // Not technically required, but this makes the fact that `ctx`
            // needs to live until this point explicit.
            drop(ctx);
            ret
        })
    }
fn enter < S , F , R > ( sleep : & mut S , f : F ) -> R where F : FnOnce ( & mut Context ) -> R , S : Sleep < Wakeup = T > , { let mut runner = TaskRunner :: new ( sleep . wakeup ( ) ) ; CURRENT . with ( | current | { // Make sure that another task runner is not set. // // This should not be ever possible due to how `set_schedule` // is setup, but better safe than sorry! assert ! ( current schedule get ( ) is_none ( ) ) ; // Enter an execution scope let mut ctx = Context { cancel : & current . cancel , } ; // Set the scheduler to the TLS and perform setup work, // returning a future to execute. // // This could possibly suubmit other futures for execution. let ret = current . set_schedule ( & mut runner . scheduler as & mut Schedule , | | { f ( & mut ctx ) } ) ; // Execute the runner. // // This function will not return until either // // a) All futures have completed execution // b) `cancel_all_spawned` is called, forcing the executor to // return. runner . run ( sleep , current ) ; // Not technically required, but this makes the fact that `ctx` // needs to live until this point explicit. drop ( ctx ) ; ret } ) }
Enter a new `TaskRunner` context
This function handles advancing the scheduler state and blocking while
listening for notified futures.
Enter a new ` TaskRunner ` context This function handles advancing the scheduler state and blocking while listening for notified futures .
sleep
&mut S
f
F
sleep
&mut S
f
F