summaryrefslogtreecommitdiff
path: root/runtime/js/12_io.js
diff options
context:
space:
mode:
authorAndreu Botella <abb@randomunok.com>2021-12-16 12:57:26 +0100
committerGitHub <noreply@github.com>2021-12-16 12:57:26 +0100
commit01a6b66034b53dbeffaa12d1d408066a1bc28643 (patch)
tree020291ed0b71562b6376bda2989925f105f6fadd /runtime/js/12_io.js
parent9ffc7edc23444be8bdcc1befd3709b309780e3d1 (diff)
feat: support abort reasons in Deno APIs and `WebSocketStream` (#13066)
Diffstat (limited to 'runtime/js/12_io.js')
-rw-r--r--runtime/js/12_io.js15
1 files changed, 6 insertions, 9 deletions
diff --git a/runtime/js/12_io.js b/runtime/js/12_io.js
index 1dd162965..213e0a1ee 100644
--- a/runtime/js/12_io.js
+++ b/runtime/js/12_io.js
@@ -7,7 +7,6 @@
((window) => {
const core = window.Deno.core;
- const { DOMException } = window.__bootstrap.domException;
const {
Uint8Array,
ArrayPrototypePush,
@@ -123,7 +122,8 @@
async function readAllInner(r, options) {
const buffers = [];
const signal = options?.signal ?? null;
- while (!signal?.aborted) {
+ while (true) {
+ signal?.throwIfAborted();
const buf = new Uint8Array(READ_PER_ITER);
const read = await r.read(buf);
if (typeof read == "number") {
@@ -132,9 +132,7 @@
break;
}
}
- if (signal?.aborted) {
- throw new DOMException("The read operation was aborted.", "AbortError");
- }
+ signal?.throwIfAborted();
return concatBuffers(buffers);
}
@@ -200,7 +198,8 @@
const buf = new Uint8Array(size + 1); // 1B to detect extended files
let cursor = 0;
const signal = options?.signal ?? null;
- while (!signal?.aborted && cursor < size) {
+ while (cursor < size) {
+ signal?.throwIfAborted();
const sliceEnd = MathMin(size + 1, cursor + READ_PER_ITER);
const slice = buf.subarray(cursor, sliceEnd);
const read = await r.read(slice);
@@ -210,9 +209,7 @@
break;
}
}
- if (signal?.aborted) {
- throw new DOMException("The read operation was aborted.", "AbortError");
- }
+ signal?.throwIfAborted();
// Handle truncated or extended files during read
if (cursor > size) {