# HG changeset patch # User Goffi # Date 1622726503 -7200 # Node ID aa58451b77ba973b495f22d2dfef57625eff62a5 # Parent 60d3861e5996ca1eed7cabbc0038aa3b79aabdfa tools (utils): new `ensure_deferred` decorator diff -r 60d3861e5996 -r aa58451b77ba sat/tools/utils.py --- 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