mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 11:34:18 +00:00
✨ Add AsyncLambda
This commit is contained in:
parent
33b04f2a0a
commit
3754f5cca7
1 changed files with 16 additions and 0 deletions
|
@ -304,6 +304,21 @@ class Check(CheckBase):
|
||||||
return self.error
|
return self.error
|
||||||
|
|
||||||
|
|
||||||
|
class AsyncLambda(Wrench):
|
||||||
|
"""
|
||||||
|
Apply an asyncronous function over the received objects.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, func: t.Callable[[t.Any], t.Awaitable[t.Any]]):
|
||||||
|
self.func: t.Callable[[t.Any], t.Awaitable[t.Any]] = func
|
||||||
|
"""
|
||||||
|
The function to apply.
|
||||||
|
"""
|
||||||
|
|
||||||
|
async def filter(self, obj: t.Any) -> t.Any:
|
||||||
|
return await self.func(obj)
|
||||||
|
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
"Check",
|
"Check",
|
||||||
"CheckBase",
|
"CheckBase",
|
||||||
|
@ -318,4 +333,5 @@ __all__ = (
|
||||||
"Type",
|
"Type",
|
||||||
"Wrench",
|
"Wrench",
|
||||||
"WrenchException",
|
"WrenchException",
|
||||||
|
"AsyncLambda",
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue