@@ -77,13 +77,13 @@ def __init__(
7777 async def stream (
7878 self , cursor : StreamCursor = StreamCursor .FROM_FIRST
7979 ) -> "AsyncIterator[T]" :
80+ client = await Supervisor .instance ().client ()
81+
8082 last_entry_id : str = cursor .value
8183 last_stream_read : float = current_time ()
8284
8385 while True :
84- raw_message : RawStreamEntry | None = await (
85- await Supervisor .instance ().client ()
86- ).xread (
86+ raw_message : RawStreamEntry | None = await client .xread (
8787 {self ._stream_key : last_entry_id },
8888 options = StreamReadOptions (
8989 block_ms = Supervisor .instance ().config .io_read_timeout , count = 1
@@ -104,6 +104,7 @@ async def stream(
104104 Supervisor .instance ().config .io_read_pending_timeout ,
105105 )
106106
107+ await anyio .lowlevel .checkpoint ()
107108 continue
108109
109110 message = StreamEntry (raw_message )
@@ -161,15 +162,13 @@ async def write(self, value: "T") -> None:
161162 elif value .name != self .name :
162163 raise MismatchedIOError ("write" , self .name , value .name )
163164
164- await (await Supervisor .instance ().client ()).xadd (
165- self ._stream_key , [("ioval" , self ._serializer .dump (value ))]
166- )
165+ client = await Supervisor .instance ().client ()
166+ await client .xadd (self ._stream_key , [("ioval" , self ._serializer .dump (value ))])
167167
168168 async def complete (self ) -> None :
169- await (await Supervisor .instance ().client ()).set (self ._completion_key , b"true" )
169+ client = await Supervisor .instance ().client ()
170+ await client .set (self ._completion_key , b"true" )
170171
171172 async def is_complete (self ) -> bool :
172- return (
173- await (await Supervisor .instance ().client ()).get (self ._completion_key )
174- == b"true"
175- )
173+ client = await Supervisor .instance ().client ()
174+ return await client .get (self ._completion_key ) == b"true"
0 commit comments