tc39 / proposal-cancelable-promises

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

Cancel.isCancel #32

Closed bergus closed 7 years ago

bergus commented 8 years ago

If custom promise libraries (that don't just subclass the builtin Promise) want to support the new cancellation approach, they'll need a way to detect objects with a [[CancelBrand]] so that they can avoid to fire their rejection tracking. I suggest we include a Cancel.isCancel function for that, analogous to Array.isArray.

domenic commented 8 years ago

User-space brand detection should check .constructor.name. This is not foolproof, but user-space branding code is in general not good, and something the proposal intentionally does not support.

bergus commented 8 years ago

OK, if you intentionally don't want to limit functionality then fine (though I don't necessarily get your reasoning).

domenic commented 8 years ago

I'll reopen this for committee discussion. Although I don't like to support such branding, it's true this is a primitive currently only granted to the language, and we should see what the committee thinks.

bergus commented 8 years ago

Ah, actually we can extract it from the language primitives:

function isCancel(e) {
    try {
        throw e;
    } else {
        return true;
    } finally {
        return false;
    }
}

but that's horrible code and I'd much rather see a builtin function for this. Thanks for reopening.