~divmod-dev/divmod.org/trunk

« back to all changes in this revision

Viewing changes to Epsilon/epsilon/cooperator.py

  • Committer: Jean-Paul Calderone
  • Date: 2014-06-29 20:33:04 UTC
  • mfrom: (2749.1.1 remove-epsilon-1325289)
  • Revision ID: exarkun@twistedmatrix.com-20140629203304-gdkmbwl1suei4m97
mergeĀ lp:~exarkun/divmod.org/remove-epsilon-1325289

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
from twisted.application.service import Service
3
 
from twisted.internet.task import SchedulerStopped, Cooperator, coiterate
4
 
 
5
 
def iterateInReactor(i, delay=None):
6
 
    """
7
 
    Cooperatively iterate over the given iterator.
8
 
 
9
 
    @see: L{twisted.internet.task.coiterate}.
10
 
    """
11
 
    return coiterate(i)
12
 
 
13
 
 
14
 
class SchedulingService(Service):
15
 
    """
16
 
    Simple L{IService} implementation.
17
 
    """
18
 
    def __init__(self):
19
 
        self.coop = Cooperator(started=False)
20
 
 
21
 
    def addIterator(self, iterator):
22
 
        return self.coop.coiterate(iterator)
23
 
 
24
 
    def startService(self):
25
 
        self.coop.start()
26
 
 
27
 
    def stopService(self):
28
 
        self.coop.stop()
29
 
 
30
 
__all__ = [
31
 
    'SchedulerStopped', 'Cooperator',
32
 
    'SchedulingService', 'iterateInReactor']