News for hackers. Stuff that matters.
Re:JavaScript Cancelable Promises Proposal by numtel on Thursday May 26, 2016 @02:50PM (#11780511)
It's not that difficult to extend Promises. Show some code that's easy to follow. If cancelled/canceled is too confusing, there are synonyms.

    function longTask() {
      return new AbortablePromise((resolve, reject, onAbort) => {
        const timer = setTimeout(resolve, 1000);
        onAbort(reason => clearTimeout(timer));
      });
    }

    const myTask = longTask
      .aborted(reason => console.log('Aborted'))
      .then(result => console.log('Done'))
      .catch(reason => console.log('Error'));

    setTimeout(() => myTask.abort('Changed my mind'), 300);
I did something similar with reporting progress: https://github.com/numtel/progress-promise

There are no comments on this comment yet.