예제 #1
0
def make_batched_timer(bucket_seconds, chunk_size=100):
    """
    Creates and returns an object implementing
    :class:`txaio.IBatchedTimer`.

    :param bucket_seconds: the number of seconds in each bucket. That
        is, a value of 5 means that any timeout within a 5 second
        window will be in the same bucket, and get notified at the
        same time. This is only accurate to "milliseconds".

    :param chunk_size: when "doing" the callbacks in a particular
        bucket, this controls how many we do at once before yielding to
        the reactor.
    """

    def get_seconds():
        return _get_loop().seconds()

    def create_delayed_call(delay, fun, *args, **kwargs):
        return _get_loop().callLater(delay, fun, *args, **kwargs)

    return _BatchedTimer(
        bucket_seconds * 1000.0, chunk_size,
        seconds_provider=get_seconds,
        delayed_call_creator=create_delayed_call,
    )
예제 #2
0
    def make_batched_timer(self, bucket_seconds, chunk_size=100):
        """
        Creates and returns an object implementing
        :class:`txaio.IBatchedTimer`.

        :param bucket_seconds: the number of seconds in each bucket. That
            is, a value of 5 means that any timeout within a 5 second
            window will be in the same bucket, and get notified at the
            same time. This is only accurate to "milliseconds".

        :param chunk_size: when "doing" the callbacks in a particular
            bucket, this controls how many we do at once before yielding to
            the reactor.
        """
        def get_seconds():
            return self._get_loop().seconds()

        def create_delayed_call(delay, fun, *args, **kwargs):
            return self._get_loop().callLater(delay, fun, *args, **kwargs)

        return _BatchedTimer(
            bucket_seconds * 1000.0,
            chunk_size,
            seconds_provider=get_seconds,
            delayed_call_creator=create_delayed_call,
        )