summaryrefslogtreecommitdiff
path: root/runtime/js/12_io.js
diff options
context:
space:
mode:
authorBenjamin Gruenbaum <benjamingr@gmail.com>2021-06-22 18:45:26 +0300
committerGitHub <noreply@github.com>2021-06-22 11:45:26 -0400
commit20b0a5125a80c027f21472eec98f29e5e35629fb (patch)
treef6551848efdd0c1ae87144e78da4c127b46f51ed /runtime/js/12_io.js
parent9c0b41e24bc5f4ec08c62517f40b74506ac9f0d1 (diff)
feat(core): support AbortSignal in readFile (#10943)
Diffstat (limited to 'runtime/js/12_io.js')
-rw-r--r--runtime/js/12_io.js11
1 files changed, 9 insertions, 2 deletions
diff --git a/runtime/js/12_io.js b/runtime/js/12_io.js
index 8df3de92f..d2b2127a6 100644
--- a/runtime/js/12_io.js
+++ b/runtime/js/12_io.js
@@ -110,9 +110,12 @@
const READ_PER_ITER = 32 * 1024;
async function readAll(r) {
+ return await readAllInner(r);
+ }
+ async function readAllInner(r, options) {
const buffers = [];
-
- while (true) {
+ const signal = options?.signal ?? null;
+ while (!signal?.aborted) {
const buf = new Uint8Array(READ_PER_ITER);
const read = await r.read(buf);
if (typeof read == "number") {
@@ -121,6 +124,9 @@
break;
}
}
+ if (signal?.aborted) {
+ throw new DOMException("The read operation was aborted.", "AbortError");
+ }
let totalLen = 0;
for (const buf of buffers) {
@@ -177,6 +183,7 @@
write,
writeSync,
readAll,
+ readAllInner,
readAllSync,
};
})(this);