tc39 / proposal-cancelable-promises

Former home of the now-withdrawn cancelable promises proposal for JavaScript
Other
375 stars 29 forks source link

Promise executor `cancel` callback? #37

Closed bergus closed 8 years ago

bergus commented 8 years ago

From the meeting notes:

With the proposal as it is:

function delay(ms, cancelToken) {
  return new Promise((resolve, reject, cancel) => {
    const id = setTimeout(resolve, ms);
    if (!cancelToken) return;
    cancelToken.promise.then(cancelation => {
      cancel(cancelation);
      clearTimeout(id);
    });
  });
}

JHD: Would have to pass cancelation through that cancel function?

DD: Yes

I'm confused, this does seem to contradict the current draft spec text. Wouldn't it need to be

function delay(ms, cancelToken) {
  return new Promise((resolve, reject) => { // no cancel callback
    const id = setTimeout(resolve, ms);
    if (!cancelToken) return;
    cancelToken.promise.then(cancelation => {
      reject(cancelation); // call reject() here
      clearTimeout(id);
    });
  });
}

You even affirmed the cancel usage to Jordan. Do you plan to re-introduce this?

domenic commented 8 years ago

This appears to be bad meeting notes. I was trying to explain that the slides had a typo.

bergus commented 8 years ago

Ah, the mistake is also in the example here.