summaryrefslogtreecommitdiff
path: root/runtime/js/40_write_file.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/40_write_file.js
parent9ffc7edc23444be8bdcc1befd3709b309780e3d1 (diff)
feat: support abort reasons in Deno APIs and `WebSocketStream` (#13066)
Diffstat (limited to 'runtime/js/40_write_file.js')
-rw-r--r--runtime/js/40_write_file.js21
1 files changed, 10 insertions, 11 deletions
diff --git a/runtime/js/40_write_file.js b/runtime/js/40_write_file.js
index 6ced4e066..bb3f91789 100644
--- a/runtime/js/40_write_file.js
+++ b/runtime/js/40_write_file.js
@@ -13,9 +13,7 @@
data,
options = {},
) {
- if (options?.signal?.aborted) {
- throw new DOMException("The write operation was aborted.", "AbortError");
- }
+ options.signal?.throwIfAborted();
if (options.create !== undefined) {
const create = !!options.create;
if (!create) {
@@ -73,14 +71,15 @@
const signal = options?.signal ?? null;
let nwritten = 0;
- 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");
+ try {
+ while (nwritten < data.length) {
+ signal?.throwIfAborted();
+ nwritten += await file.write(
+ TypedArrayPrototypeSubarray(data, nwritten),
+ );
+ }
+ } finally {
+ file.close();
}
}