- From: Andrea Giammarchi <notifications@github.com>
- Date: Mon, 30 Mar 2015 07:13:35 -0700
- To: whatwg/fetch <fetch@noreply.github.com>
Received on Monday, 30 March 2015 14:14:01 UTC
FYI I've updated the code so that you can provide a value when canceled.
```js
// will be resolved
new Promise(function ($res, $rej, ifCanceled) {
var internal = setTimeout($rej, 1000);
ifCanceled(function () {
clearTimeout(internal);
});
})
// will be resolved without executing
.then(
function () {
console.log('on time');
},
function () {
console.log('error');
}
)
.cancel({beacuse:'reason'})
// will simply execute and resolve
.then(function (value) {
console.log(value);
});
```
Invoking cancel again can be done internally (`ifCanceled` returns such method) or externally so the first in charge of canceling will be also eventually in charge of passing an arbitrary resolution for such cancellation.
@getify I'm using timers and events to test this stuff, I don't even care much about fetch itself in terms of solution. fetch is just Yet Another Case when you want to cancel something at any time.
---
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/27#issuecomment-87695054
Received on Monday, 30 March 2015 14:14:01 UTC