AbortController 类


用于在选定的基于 Promise 的 API 中发出取消信号的实用工具类。 该 API 基于 Web API AbortController

const ac = new AbortController();

ac.signal.addEventListener('abort', () => console.log('Aborted!'),
                           { once: true });

ac.abort();

console.log(ac.signal.aborted);  // 打印 true

A utility class used to signal cancelation in selected Promise-based APIs. The API is based on the Web API AbortController.

const ac = new AbortController();

ac.signal.addEventListener('abort', () => console.log('Aborted!'),
                           { once: true });

ac.abort();

console.log(ac.signal.aborted);  // Prints True