diff --git a/.changeset/chilly-jars-drop.md b/.changeset/chilly-jars-drop.md new file mode 100644 index 00000000..7197a369 --- /dev/null +++ b/.changeset/chilly-jars-drop.md @@ -0,0 +1,5 @@ +--- +"@dassie/lib-protocol-stream": patch +--- + +Immediately stop sending when scope is disposed diff --git a/packages/lib-protocol-stream/src/connection/send-until-done.ts b/packages/lib-protocol-stream/src/connection/send-until-done.ts index ed1316e3..6ac6b6dc 100644 --- a/packages/lib-protocol-stream/src/connection/send-until-done.ts +++ b/packages/lib-protocol-stream/src/connection/send-until-done.ts @@ -14,7 +14,7 @@ export function sendUntilDone(state: ConnectionState) { state.sendLoopPromise = (async function sendLoop() { for (;;) { - const hasWork = hasWorkToDo(state) + const hasWork = !state.scope.isDisposed && hasWorkToDo(state) // If we have no more new work to do and no work is in progress, that // means we are fully done and can end the loop.