Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Commit

Permalink
Close stream after sink
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoPolo committed Oct 31, 2022
1 parent f6b7f96 commit b58ee11
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,18 @@ async function webtransportBiDiStreamToStream (bidiStream: any, streamId: string
}
})(),
sink: async function (source: Source<Uint8Array | Uint8ArrayList>) {
for await (const chunks of source) {
if (chunks.constructor === Uint8Array) {
await writer.write(chunks)
} else {
for (const buf of chunks) {
await writer.write(buf)
try {
for await (const chunks of source) {
if (chunks.constructor === Uint8Array) {
await writer.write(chunks)
} else {
for (const buf of chunks) {
await writer.write(buf)
}
}
}
} finally {
stream.closeWrite()
}
}
}
Expand Down

0 comments on commit b58ee11

Please sign in to comment.