'Return a task that drives the TaskRunner.'

def as_task(self, timeout=None, progress_callback=None):

    resuming = self.started()
    if (not resuming):
        self.start(timeout=timeout)
    elif (timeout is not None):
        new_timeout = Timeout(self, timeout)
        if ((self._timeout is None) or (new_timeout < self._timeout)):
            self._timeout = new_timeout
    done = (self.step() if resuming else self.done())
    while (not done):
        try:
            (yield)
            if (progress_callback is not None):
                progress_callback()
        except GeneratorExit:
            self.cancel()
            raise
        except:
            self._done = True
            try:
                self._runner.throw(*sys.exc_info())
            except StopIteration:
                return
            else:
                self._done = False
        else:
            done = self.step()
