Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
3539:60d3861e5996 | 3540:aa58451b77ba |
---|---|
122 return wrapper | 122 return wrapper |
123 | 123 |
124 | 124 |
125 def as_future(d): | 125 def as_future(d): |
126 return d.asFuture(asyncio.get_event_loop()) | 126 return d.asFuture(asyncio.get_event_loop()) |
127 | |
128 | |
129 def ensure_deferred(func): | |
130 """Decorator to apply ensureDeferred to a function | |
131 | |
132 to be used when the function is called by third party library (e.g. wokkel) | |
133 Otherwise, it's better to use ensureDeferred as early as possible. | |
134 """ | |
135 def wrapper(*args, **kwargs): | |
136 return defer.ensureDeferred(func(*args, **kwargs)) | |
137 return wrapper | |
127 | 138 |
128 | 139 |
129 def xmpp_date(timestamp=None, with_time=True): | 140 def xmpp_date(timestamp=None, with_time=True): |
130 """Return date according to XEP-0082 specification | 141 """Return date according to XEP-0082 specification |
131 | 142 |