add sleep helper; some cosmetics
This commit is contained in:
parent
b6ed6f7b81
commit
af963e6fbe
@ -65,14 +65,11 @@ Please refer to the `documentation <https://txaio.readthedocs.io/en/latest/>`_ f
|
||||
.. |Version| image:: https://img.shields.io/pypi/v/txaio.svg
|
||||
:target: https://pypi.python.org/pypi/txaio
|
||||
|
||||
.. |Master Branch| image:: https://img.shields.io/badge/branch-master-orange.svg
|
||||
:target: https://travis-ci.org/crossbario/txaio.svg?branch=master
|
||||
|
||||
.. |Build Status| image:: https://travis-ci.org/crossbario/txaio.svg?branch=master
|
||||
:target: https://travis-ci.org/crossbario/txaio
|
||||
|
||||
.. |Coverage| image:: https://img.shields.io/codecov/c/github/crossbario/txaio/master.svg
|
||||
.. |Coverage| image:: https://codecov.io/github/crossbario/txaio/coverage.svg?branch=master
|
||||
:target: https://codecov.io/github/crossbario/txaio
|
||||
|
||||
.. |Docs| image:: https://img.shields.io/badge/docs-latest-brightgreen.svg?style=flat
|
||||
.. |Docs| image:: https://readthedocs.org/projects/txaio/badge/?version=latest
|
||||
:target: https://txaio.readthedocs.io/en/latest/
|
||||
|
@ -65,34 +65,36 @@ __all__ = (
|
||||
|
||||
'config', # the config instance, access via attributes
|
||||
|
||||
'create_future', # create a Future (can be already resolved/errored)
|
||||
'create_future', # create a Future (can be already resolved/errored)
|
||||
'create_future_success',
|
||||
'create_future_error',
|
||||
'create_failure', # return an object implementing IFailedFuture
|
||||
'as_future', # call a method, and always return a Future
|
||||
'is_future', # True for Deferreds in tx and Futures, @coroutines in asyncio
|
||||
'reject', # errback a Future
|
||||
'resolve', # callback a Future
|
||||
'add_callbacks', # add callback and/or errback
|
||||
'gather', # return a Future waiting for several other Futures
|
||||
'is_called', # True if the Future has a result
|
||||
'create_failure', # return an object implementing IFailedFuture
|
||||
'as_future', # call a method, and always return a Future
|
||||
'is_future', # True for Deferreds in tx and Futures, @coroutines in asyncio
|
||||
'reject', # errback a Future
|
||||
'resolve', # callback a Future
|
||||
'add_callbacks', # add callback and/or errback
|
||||
'gather', # return a Future waiting for several other Futures
|
||||
'is_called', # True if the Future has a result
|
||||
|
||||
'call_later', # call the callback after the given delay seconds
|
||||
'call_later', # call the callback after the given delay seconds
|
||||
|
||||
'failure_message', # a printable error-message from a IFailedFuture
|
||||
'failure_traceback', # returns a traceback instance from an IFailedFuture
|
||||
'failure_format_traceback', # a string, the formatted traceback
|
||||
'failure_message', # a printable error-message from a IFailedFuture
|
||||
'failure_traceback', # returns a traceback instance from an IFailedFuture
|
||||
'failure_format_traceback', # a string, the formatted traceback
|
||||
|
||||
'make_batched_timer', # create BatchedTimer/IBatchedTimer instances
|
||||
'make_batched_timer', # create BatchedTimer/IBatchedTimer instances
|
||||
|
||||
'make_logger', # creates an object implementing ILogger
|
||||
'start_logging', # initializes logging (may grab stdin at this point)
|
||||
'set_global_log_level', # Set the global log level
|
||||
'get_global_log_level', # Get the global log level
|
||||
'make_logger', # creates an object implementing ILogger
|
||||
'start_logging', # initializes logging (may grab stdin at this point)
|
||||
'set_global_log_level', # Set the global log level
|
||||
'get_global_log_level', # Get the global log level
|
||||
'add_log_categories',
|
||||
|
||||
'IFailedFuture', # describes API for arg to errback()s
|
||||
'ILogger', # API for logging
|
||||
'IFailedFuture', # describes API for arg to errback()s
|
||||
'ILogger', # API for logging
|
||||
|
||||
'sleep', # little helper for inline sleeping
|
||||
)
|
||||
|
||||
|
||||
|
@ -75,3 +75,5 @@ add_log_categories = _throw_usage_error
|
||||
|
||||
IFailedFuture = _throw_usage_error
|
||||
ILogger = _throw_usage_error
|
||||
|
||||
sleep = _throw_usage_error
|
||||
|
@ -1 +1 @@
|
||||
__version__ = u'2.6.0'
|
||||
__version__ = u'2.6.1'
|
||||
|
12
txaio/aio.py
12
txaio/aio.py
@ -424,3 +424,15 @@ def set_global_log_level(level):
|
||||
|
||||
def get_global_log_level():
|
||||
return _log_level
|
||||
|
||||
|
||||
def sleep(delay, loop=None):
|
||||
"""
|
||||
Inline sleep for use in co-routines.
|
||||
|
||||
:param delay: Time to sleep in seconds.
|
||||
:type delay: float
|
||||
:param reactor: The asyncio loop to use.
|
||||
:type reactor: None (to use the default loop) or a loop.
|
||||
"""
|
||||
raise Exception('not implemented yet')
|
||||
|
20
txaio/tx.py
20
txaio/tx.py
@ -536,3 +536,23 @@ def set_global_log_level(level):
|
||||
|
||||
def get_global_log_level():
|
||||
return _log_level
|
||||
|
||||
|
||||
def sleep(delay, reactor=None):
|
||||
"""
|
||||
Inline sleep for use in co-routines (Twisted ``inlineCallback`` decorated functions).
|
||||
|
||||
.. seealso::
|
||||
* `twisted.internet.defer.inlineCallbacks <http://twistedmatrix.com/documents/current/api/twisted.internet.defer.html#inlineCallbacks>`__
|
||||
* `twisted.internet.interfaces.IReactorTime <http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.IReactorTime.html>`__
|
||||
|
||||
:param delay: Time to sleep in seconds.
|
||||
:type delay: float
|
||||
:param reactor: The Twisted reactor to use.
|
||||
:type reactor: None or provider of ``IReactorTime``.
|
||||
"""
|
||||
if not reactor:
|
||||
from twisted.internet import reactor
|
||||
d = Deferred()
|
||||
reactor.callLater(delay, d.callback, None)
|
||||
return d
|
||||
|
Loading…
x
Reference in New Issue
Block a user