Mercurial > libervia-backend
diff sat/tools/utils.py @ 3540:aa58451b77ba
tools (utils): new `ensure_deferred` decorator
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 03 Jun 2021 15:21:43 +0200 |
parents | f9a5b810f14d |
children | 0a87cae85746 |
line wrap: on
line diff
--- a/sat/tools/utils.py Thu Jun 03 15:21:43 2021 +0200 +++ b/sat/tools/utils.py Thu Jun 03 15:21:43 2021 +0200 @@ -126,6 +126,17 @@ return d.asFuture(asyncio.get_event_loop()) +def ensure_deferred(func): + """Decorator to apply ensureDeferred to a function + + to be used when the function is called by third party library (e.g. wokkel) + Otherwise, it's better to use ensureDeferred as early as possible. + """ + def wrapper(*args, **kwargs): + return defer.ensureDeferred(func(*args, **kwargs)) + return wrapper + + def xmpp_date(timestamp=None, with_time=True): """Return date according to XEP-0082 specification