Last active
July 15, 2017 04:17
-
-
Save bekzod/68e8fc1c739745b6a5bdb12e99badfd4 to your computer and use it in GitHub Desktop.
rsvp-vs-promise-then.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var rsvp = require('rsvp'); | |
class TestPromiseFromNative extends Promise { | |
then(onFulfillment, ...args) { | |
return super.then(result => isolate(onFulfillment, result), ...args); | |
} | |
} | |
class TestPromiseFromRSVP extends rsvp.Promise { | |
then(onFulfillment, ...args) { | |
return super.then(result => isolate(onFulfillment, result), ...args); | |
} | |
} | |
var p = new TestPromiseFromNative(function(resolve) { | |
resolve(); | |
}) | |
.then(null) | |
.catch(console.log) | |
var p = new TestPromiseFromRSVP(function(resolve) { | |
resolve(); | |
}) | |
.then(null) | |
.catch(console.log) | |
function isolate(onFulfillment, result) { | |
// Reset lastPromise for nested helpers | |
lastPromise = null; | |
let value = onFulfillment(result); | |
let promise = lastPromise; | |
lastPromise = null; | |
return value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment