[Javascript] Cancel A Promise Using AbortController

The AbortController interface enables us to cancel a one or more DOM requests. In this lesson, we will demonstrate how to use the controller to cancel a Javascript Promise before it is resolved.

const controller = new AbortController();
const signal = controller.signal;

The controller only has one method:

controller.abort();

When you do this, it notifies the signal:

 
signal.addEventListener('abort', () => {
  // Logs true:
  console.log(signal.aborted);
});

Read More

原文地址:https://www.cnblogs.com/Answer1215/p/9915867.html