[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

 

posted @ 2018-11-06 16:06  Zhentiw  阅读(340)  评论(0编辑  收藏  举报