summaryrefslogtreecommitdiff
path: root/runtime/js/40_write_file.js
diff options
context:
space:
mode:
authorBenjamin Gruenbaum <benjamingr@gmail.com>2021-08-06 20:21:29 +0300
committerGitHub <noreply@github.com>2021-08-06 10:21:29 -0700
commit2b53602d3c798b68db4ce986546d3434b986096a (patch)
tree8b8a1bf86d3f890302b50f21ce0632df1e2d9728 /runtime/js/40_write_file.js
parent466d3df9d1ff43e16e1a2c20b7792de664547b48 (diff)
feat: support AbortSignal in writeFile (#11568)
Diffstat (limited to 'runtime/js/40_write_file.js')
-rw-r--r--runtime/js/40_write_file.js10
1 files changed, 9 insertions, 1 deletions
diff --git a/runtime/js/40_write_file.js b/runtime/js/40_write_file.js
index def9f6fee..6ced4e066 100644
--- a/runtime/js/40_write_file.js
+++ b/runtime/js/40_write_file.js
@@ -13,6 +13,9 @@
data,
options = {},
) {
+ if (options?.signal?.aborted) {
+ throw new DOMException("The write operation was aborted.", "AbortError");
+ }
if (options.create !== undefined) {
const create = !!options.create;
if (!create) {
@@ -68,12 +71,17 @@
await chmod(path, options.mode);
}
+ const signal = options?.signal ?? null;
let nwritten = 0;
- while (nwritten < data.length) {
+ while (!signal?.aborted && nwritten < data.length) {
nwritten += await file.write(TypedArrayPrototypeSubarray(data, nwritten));
}
file.close();
+
+ if (signal?.aborted) {
+ throw new DOMException("The write operation was aborted.", "AbortError");
+ }
}
function writeTextFileSync(