Killing `Promise.fulfill`

Kevin Smith zenparsing at gmail.com
Mon Aug 19 20:14:54 PDT 2013


Implementation:

    function unwrap(value) {
        return Promise.resolve(value).then(v => isPromise(v) ? unwrap(v) :
v);
    }

    Promise.when = value => unwrap(value);

Test:

    var promise = new Promise(r => {
        r.fulfill(new Promise(r => { r.fulfill(1); }));
    });

    promise.then(val => console.log(val.then ? "promise" : "value"));
    Promise.when(promise).then(val => console.log(val.then ? "promise" :
"value"));

    >> promise
    >> value

{ Kevin }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130819/00b55ac4/attachment.html>


More information about the es-discuss mailing list