fix(sdk): preserve queued events on stream close
Signed-off-by: Lanre Shittu <136805224+Shizoqua@users.noreply.github.com>
This commit is contained in:
1 parent
972cdde8da
commit
816a999cac
3 files changed
+27
-7
No files matched your search
+1
-1
@@ -302,7 +302,7 @@ class Nanobot:
|
||||
))
|
||||
raise
|
||||
finally:
|
||||
emitter.close()
|
||||
await emitter.close()
|
||||
|
||||
task = asyncio.create_task(_run())
|
||||
return RunStream(task, queue)
|
||||
|
||||
@@ -158,15 +158,11 @@ class SDKStreamEmitter:
|
||||
resuming=resuming,
|
||||
))
|
||||
|
||||
def close(self) -> None:
|
||||
async def close(self) -> None:
|
||||
if self._closed:
|
||||
return
|
||||
self._closed = True
|
||||
if self._queue.full():
|
||||
with suppress(asyncio.QueueEmpty):
|
||||
self._queue.get_nowait()
|
||||
with suppress(asyncio.QueueFull):
|
||||
self._queue.put_nowait(_STREAM_SENTINEL)
|
||||
await self._queue.put(_STREAM_SENTINEL)
|
||||
|
||||
|
||||
class SDKStreamingHook(AgentHook):
|
||||
|
||||
Reference in new issue
Block a user