This commit is contained in:
@@ -6,10 +6,12 @@ from .private import (
|
|||||||
ExceptionHandlerOutcome,
|
ExceptionHandlerOutcome,
|
||||||
tmpdir,
|
tmpdir,
|
||||||
decorator_with_kwargs,
|
decorator_with_kwargs,
|
||||||
classproperty
|
classproperty,
|
||||||
|
AsyncQueueIterator
|
||||||
)
|
)
|
||||||
from .maybe import Maybe
|
from .maybe import Maybe
|
||||||
from .notification import TopicManager, Subscriber
|
from .notification import TopicManager, Subscriber
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'format_filesize',
|
'format_filesize',
|
||||||
'async_retry',
|
'async_retry',
|
||||||
@@ -21,5 +23,6 @@ __all__ = [
|
|||||||
'decorator_with_kwargs',
|
'decorator_with_kwargs',
|
||||||
'classproperty',
|
'classproperty',
|
||||||
'TopicManager',
|
'TopicManager',
|
||||||
'Subscriber'
|
'Subscriber',
|
||||||
|
'AsyncQueueIterator'
|
||||||
]
|
]
|
||||||
|
@@ -53,6 +53,7 @@ class Maybe(Generic[T]):
|
|||||||
|
|
||||||
def __or__(self, alt: Maybe[T]) -> Maybe[T]:
|
def __or__(self, alt: Maybe[T]) -> Maybe[T]:
|
||||||
return self if self.is_present else alt
|
return self if self.is_present else alt
|
||||||
|
|
||||||
def or_else(self, alt: T) -> T:
|
def or_else(self, alt: T) -> T:
|
||||||
return self.value if self.is_present else alt
|
return self.value if self.is_present else alt
|
||||||
|
|
||||||
@@ -65,7 +66,7 @@ class Maybe(Generic[T]):
|
|||||||
else:
|
else:
|
||||||
raise supplier()
|
raise supplier()
|
||||||
|
|
||||||
def or_else_get(self, supplier: Callable[[], T]) -> Maybe[T]:
|
def or_else_get(self, supplier: Callable[[], Optional[T]]) -> Maybe[T]:
|
||||||
return self if self.is_present else Maybe.of_nullable(supplier())
|
return self if self.is_present else Maybe.of_nullable(supplier())
|
||||||
|
|
||||||
def if_present(self, callback: Callable[[T], U]) -> None:
|
def if_present(self, callback: Callable[[T], U]) -> None:
|
||||||
|
@@ -6,7 +6,7 @@ from inspect import signature
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from typing import Callable
|
from typing import Callable, AsyncIterator
|
||||||
|
|
||||||
|
|
||||||
def decorator_with_kwargs(decorator: Callable) -> Callable:
|
def decorator_with_kwargs(decorator: Callable) -> Callable:
|
||||||
@@ -207,16 +207,16 @@ def classproperty(func):
|
|||||||
return ClassPropertyDescriptor(func)
|
return ClassPropertyDescriptor(func)
|
||||||
|
|
||||||
|
|
||||||
class AsyncQueueIterator:
|
class AsyncQueueIterator[T]:
|
||||||
_queue: Queue
|
_queue: Queue[T]
|
||||||
|
|
||||||
def __init__(self, queue: Queue):
|
def __init__(self, queue: Queue[T]):
|
||||||
self._queue = queue
|
self._queue = queue
|
||||||
|
|
||||||
def __aiter__(self):
|
def __aiter__(self) -> AsyncIterator[T]:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
async def __anext__(self):
|
async def __anext__(self) -> [T]:
|
||||||
item = await self._queue.get()
|
item = await self._queue.get()
|
||||||
if item is None:
|
if item is None:
|
||||||
raise StopAsyncIteration
|
raise StopAsyncIteration
|
||||||
|
Reference in New Issue
Block a user