Since checking `promise.state` is synchronous, we may as well just
write a synchronous Cancel class instead:

```js
class CancelError extends Error { /* ... */ }

class Cancel {
    constructor() { this.requested = false }
    request() { this.requested = true }
    throw() { throw new CancelError() }
}

async function f(cancel) {
    await cheapOperation(cancel) // some other function might call
cancel.request() while we await here.
    if (!cancel.requested)
        await expensiveOperation(cancel)
}

let cancel = new Cancel
cancelButton.onclick = () => cancel.request()
f(cancel)
```

Wouldn't this be better than using a Promise if we are relying on a
synchronous check anyways?

On Mon, Jan 4, 2016 at 12:30 PM, Kevin Smith <zenpars...@gmail.com> wrote:
>> We have pretty sound cancellation semantics in bluebird 3.
>
>
> Cool, I'm aware that cancellable promises have been explored in depth.  I'd
> prefer to keep this thread focused on cancellation tokens though, and avoid
> comparisons.
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to