Why RSVP Deferred produces an error when the promise is called twice?
It seems that there is a difference between deferred.promise.then().finally() and deferred.promise.then(); deferred.promise.finally(). Why?
RSVP.on('error', function(reason) {
console.log('Error: ' + reason);
});
var deferred = RSVP.defer();
var deferred2 = RSVP.defer();
var deferred3 = RSVP.defer();
var promise3 = deferred3.promise;
deferred.promise.then(function() {
console.log('Resolved');
}, function() {
console.log('Rejected');
}).finally(function() {
console.log('Finally');
});
deferred2.promise.then(function() {
console.log('Resolved2');
}, function() {
console.log('Rejected2');
});
deferred2.promise.finally(function() {
console.log('Finally2');
});
promise3 = promise3.then(function() {
console.log('Resolved3');
}, function() {
console.log('Rejected');
});
promise3.finally(function() {
console.log('Finally3');
});
deferred.reject('Reject!');
deferred2.reject('Reject2!');
deferred3.reject('Reject3!');
<script src="https://cdnjs.cloudflare.com/ajax/libs/rsvp/4.8.1/rsvp.js"></script>
EDIT: I found out how to fix the issue. See the Deferred3 in the code.
I found that
promise.then()(and other methods) returns a modified promise so you have to chain thethen,finally,catch... methods or you have to save thepromiseeach time.