diff options
author | Luca Casonato <lucacasonato@yahoo.com> | 2021-06-06 15:37:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-06 15:37:17 +0200 |
commit | 1fb2e23a6747a4f774e63639eb522cb34aadbf42 (patch) | |
tree | 4cf18f9519b64ae923aa99ad9ba3a0bedebf6b5b /extensions/fetch/22_body.js | |
parent | 3f9187c366be362a219274ded5be9e679b96af98 (diff) |
feat(fetch): implement abort (#10863)
This commit introduces fetch aborting via an AbortSignal.
Diffstat (limited to 'extensions/fetch/22_body.js')
-rw-r--r-- | extensions/fetch/22_body.js | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/extensions/fetch/22_body.js b/extensions/fetch/22_body.js index f0c7ac8bd..dcf1128a7 100644 --- a/extensions/fetch/22_body.js +++ b/extensions/fetch/22_body.js @@ -20,7 +20,8 @@ const { parseFormData, formDataFromEntries, encodeFormData } = globalThis.__bootstrap.formData; const mimesniff = globalThis.__bootstrap.mimesniff; - const { isReadableStreamDisturbed } = globalThis.__bootstrap.streams; + const { isReadableStreamDisturbed, errorReadableStream } = + globalThis.__bootstrap.streams; class InnerBody { /** @type {ReadableStream<Uint8Array> | { body: Uint8Array, consumed: boolean }} */ @@ -106,6 +107,22 @@ } } + cancel(error) { + if (this.streamOrStatic instanceof ReadableStream) { + this.streamOrStatic.cancel(error); + } else { + this.streamOrStatic.consumed = true; + } + } + + error(error) { + if (this.streamOrStatic instanceof ReadableStream) { + errorReadableStream(this.streamOrStatic, error); + } else { + this.streamOrStatic.consumed = true; + } + } + /** * @returns {InnerBody} */ |