diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-07-19 19:49:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-19 19:49:44 +0200 |
commit | fa61956f03491101b6ef64423ea2f1f73af26a73 (patch) | |
tree | c3800702071ca78aa4dd71bdd0a59a9bbe460bdd /cli/js/web/abort_signal.ts | |
parent | 53adde866dd399aa2509d14508642fce37afb8f5 (diff) |
Port internal TS code to JS (#6793)
Co-authored-by: Ryan Dahl <ry@tinyclouds.org>
Diffstat (limited to 'cli/js/web/abort_signal.ts')
-rw-r--r-- | cli/js/web/abort_signal.ts | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/cli/js/web/abort_signal.ts b/cli/js/web/abort_signal.ts deleted file mode 100644 index b741d6534..000000000 --- a/cli/js/web/abort_signal.ts +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { EventImpl } from "./event.ts"; -import { EventTargetImpl } from "./event_target.ts"; - -export const add = Symbol("add"); -export const signalAbort = Symbol("signalAbort"); -export const remove = Symbol("remove"); - -export class AbortSignalImpl extends EventTargetImpl implements AbortSignal { - #aborted?: boolean; - #abortAlgorithms = new Set<() => void>(); - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - onabort: ((this: AbortSignal, ev: Event) => any) | null = null; - - [add](algorithm: () => void): void { - this.#abortAlgorithms.add(algorithm); - } - - [signalAbort](): void { - if (this.#aborted) { - return; - } - this.#aborted = true; - for (const algorithm of this.#abortAlgorithms) { - algorithm(); - } - this.#abortAlgorithms.clear(); - this.dispatchEvent(new EventImpl("abort")); - } - - [remove](algorithm: () => void): void { - this.#abortAlgorithms.delete(algorithm); - } - - constructor() { - super(); - this.addEventListener("abort", (evt: Event) => { - const { onabort } = this; - if (typeof onabort === "function") { - onabort.call(this, evt); - } - }); - } - - get aborted(): boolean { - return Boolean(this.#aborted); - } - - get [Symbol.toStringTag](): string { - return "AbortSignal"; - } -} - -Object.defineProperty(AbortSignalImpl, "name", { - value: "AbortSignal", - configurable: true, -}); |