'This is a sample generator which yields Deferreds when we are testing
deferral and an ascending integer count otherwise.'

def worker(self):

    i = 0
    while True:
        i += 1
        if self._doDeferNext:
            self._doDeferNext = False
            d = defer.Deferred()
            self.work.append(d)
            (yield d)
        elif self._doStopNext:
            return
        elif self._doDieNext:
            raise UnhandledException()
        else:
            self.work.append(i)
            (yield i)
