mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
feat: support abort reasons in Deno APIs and WebSocketStream
(#13066)
This commit is contained in:
parent
9ffc7edc23
commit
01a6b66034
9 changed files with 241 additions and 63 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue