Skip to content

ResettableAbortController

An AbortController that can be aborted more than once.

A plain AbortController is single-use: once aborted, its signal stays aborted forever, so it cannot back a cancel button that the user may press more than once. This one aborts the current signal and immediately replaces it, so the next operation starts with a fresh, non-aborted signal while the work that captured the previous signal still observes the abort.

Read ResettableAbortController.signal at the start of each operation. Never cache it, or the operation after the first abort starts already aborted.

Import:

import { ResettableAbortController } from 'obsidian-dev-utils/abort-controller';

Example:

const resettableAbortController = new ResettableAbortController();
await loop({
abortSignal: resettableAbortController.signal,
buildNoticeMessage: (file) => `Processing ${file.path}`,
items: app.vault.getMarkdownFiles(),
processItem: async (file) => { await processFile(file); }
});
// From a cancel button, a command, or the devtools console.
resettableAbortController.abort();

Signature:

export class ResettableAbortController

Methods

MethodReturnsDescription
abort(reason?)voidAborts the current signal and replaces it with a fresh, non-aborted one.

Links to this page: