import { abortable } from "https://deno.land/x/fun@v2.0.0/promise.ts";
Make an existing Promise somewhat abortable. While the returned promise does resolve when the abort signal occurs, the existing promise continues running in the background. For this reason it is important to catch any errors associated with the original promise and to not implement side effects in the aborted promise.
Examples
Example 1
Example 1
import { abortable, wait } from "./promise.ts";
import { pipe } from "./fn.ts";
const controller = new AbortController();
const slow = wait(1000).then(() => 1);
const wrapped = pipe(
slow,
abortable(controller.signal, msg => msg),
);
setTimeout(() => controller.abort("Hi"), 500);
// After 500ms result contains the following
// { tag: "Left", left: "Hi" }
const result = await wrapped;
Parameters
signal: AbortSignal
onAbort: (reason: unknown) => B