Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion boostedblob/boost.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import asyncio
import sys
from typing import (
Any,
AsyncIterable,
Expand All @@ -18,8 +19,12 @@
Type,
TypeVar,
Union,
TYPE_CHECKING,
)

if TYPE_CHECKING:
from _typeshed import SupportsAnext

A = TypeVar("A")
T = TypeVar("T")
R = TypeVar("R")
Expand Down Expand Up @@ -494,6 +499,15 @@ async def blocking_dequeue(self) -> Tuple[int, T]:
return ret


# version of anext that always returns a Coroutine
if sys.version_info >= (3, 10):
async def anext_cr(v: SupportsAnext[T]) -> T:
return await anext(v)
else:
async def anext_cr(v: SupportsAnext[T]) -> T:
return await v.__anext__()


class EageriseBoostable(Boostable[T]):
def __init__(self, iterable: AsyncIterator[T], executor: BoostExecutor) -> None:
super().__init__(executor)
Expand Down Expand Up @@ -544,7 +558,7 @@ async def eagerly_buffer(self) -> None:
# We can't use async for because we need to preserve exceptions
it = self.iterable.__aiter__()
while True:
task = asyncio.create_task(it.__anext__())
task = asyncio.create_task(anext_cr(it))
try:
await task
except StopAsyncIteration:
Expand Down