예제 #1
0
def repeatAlways(child, **kwargs):
    """Perpetually iterate over the child, regardless of return value.
    """
    result = None
    while True:
        try:
            visitor = core.visit(child, **kwargs)
        except StopIteration:
            continue
        while result is None:
            try:
                result = (yield visitor.next())
            except StopIteration:
                yield None
                break
예제 #2
0
파일: decorators.py 프로젝트: Gaboose/owyl
def limit(child, **kwargs):
    """Limit the child to only iterate once every period.

    Otherwise, act as an identity decorator.

    @keyword limit_period: how often to run the child, in seconds.
    """
    nowtime = time.time
    last_run = nowtime()
    period = kwargs.get('limit_period', 1.0)
    result = None
    visitor = core.visit(child, **kwargs)
    while True:
        now = nowtime()
        since_last = now - last_run
        if (since_last) <= period:
            yield None
            continue
        last_run = nowtime()
        result = visitor.next()
        yield result
예제 #3
0
def limit(child, **kwargs):
    """Limit the child to only iterate once every period.

    Otherwise, act as an identity decorator.

    @keyword limit_period: how often to run the child, in seconds.
    """
    nowtime = time.time
    last_run = nowtime()
    period = kwargs.get('limit_period', 1.0)
    result = None
    visitor = core.visit(child, **kwargs)
    while True:
        now = nowtime()
        since_last = now - last_run
        if (since_last) <= period:
            yield None
            continue
        last_run = nowtime()
        result = visitor.next()
        yield result