Skip to content

Instantly share code, notes, and snippets.

@bekzod
Last active July 15, 2017 04:17
Show Gist options
  • Save bekzod/68e8fc1c739745b6a5bdb12e99badfd4 to your computer and use it in GitHub Desktop.
Save bekzod/68e8fc1c739745b6a5bdb12e99badfd4 to your computer and use it in GitHub Desktop.
rsvp-vs-promise-then.js
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