Add finally to promise-like object.

Closes #680
This commit is contained in:
Derrick Gilland 2015-07-24 16:50:23 -04:00
parent 08ebb97ea7
commit 23930871a1
2 changed files with 37 additions and 0 deletions

View file

@ -1055,6 +1055,14 @@ var m = (function app(window, undefined) {
return propify(promise.then(resolve, reject), initialValue);
};
prop["catch"] = prop.then.bind(null, null);
prop["finally"] = function(callback){
var _callback = function(value){return m.deferred().resolve(callback(value)).promise;};
return prop.then(function(value) {
return propify(_callback(value).then(function() {return value;}), initialValue);
}, function(reason) {
return propify(_callback(reason).then(function() {throw new Error(reason);}), initialValue);
});
};
return prop;
}
//Promiz.mithril.js | Zolmeister | MIT