mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 23:44:57 -04:00
Allow spam-checker modules to be provide async methods. (#8890)
Spam checker modules can now provide async methods. This is implemented in a backwards-compatible manner.
This commit is contained in:
parent
5d34f40d49
commit
f14428b25c
19 changed files with 98 additions and 73 deletions
|
@ -15,10 +15,12 @@
|
|||
# limitations under the License.
|
||||
|
||||
import collections
|
||||
import inspect
|
||||
import logging
|
||||
from contextlib import contextmanager
|
||||
from typing import (
|
||||
Any,
|
||||
Awaitable,
|
||||
Callable,
|
||||
Dict,
|
||||
Hashable,
|
||||
|
@ -542,11 +544,11 @@ class DoneAwaitable:
|
|||
raise StopIteration(self.value)
|
||||
|
||||
|
||||
def maybe_awaitable(value):
|
||||
def maybe_awaitable(value: Union[Awaitable[R], R]) -> Awaitable[R]:
|
||||
"""Convert a value to an awaitable if not already an awaitable.
|
||||
"""
|
||||
|
||||
if hasattr(value, "__await__"):
|
||||
if inspect.isawaitable(value):
|
||||
assert isinstance(value, Awaitable)
|
||||
return value
|
||||
|
||||
return DoneAwaitable(value)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue