Skip to content

Commit 1147c01

Browse files
Editorial: fix byte stream examples to respond(0) after close()
Fix byte stream examples to respond(0) after close() Don't respond(0) if we didn't close() yet
1 parent 8bbfbf8 commit 1147c01

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

index.bs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7234,15 +7234,21 @@ function makeUDPSocketStream(host, port) {
72347234
if (controller.byobRequest) {
72357235
const v = controller.byobRequest.view;
72367236
bytesRead = socket.readInto(v.buffer, v.byteOffset, v.byteLength);
7237+
if (bytesRead === 0) {
7238+
controller.close();
7239+
}
72377240
controller.byobRequest.respond(bytesRead);
72387241
} else {
72397242
const buffer = new ArrayBuffer(DEFAULT_CHUNK_SIZE);
72407243
bytesRead = socket.readInto(buffer, 0, DEFAULT_CHUNK_SIZE);
7241-
controller.enqueue(new Uint8Array(buffer, 0, bytesRead));
7244+
if (bytesRead === 0) {
7245+
controller.close();
7246+
} else {
7247+
controller.enqueue(new Uint8Array(buffer, 0, bytesRead));
7248+
}
72427249
}
72437250

72447251
if (bytesRead === 0) {
7245-
controller.close();
72467252
return;
72477253
}
72487254

@@ -7336,6 +7342,7 @@ function makeReadableByteFileStream(filename) {
73367342
if (bytesRead === 0) {
73377343
await fileHandle.close();
73387344
controller.close();
7345+
controller.byobRequest.respond(0);
73397346
} else {
73407347
position += bytesRead;
73417348
controller.byobRequest.respond(bytesRead);

0 commit comments

Comments
 (0)