-
-
Notifications
You must be signed in to change notification settings - Fork 648
Promise.finally()
David Fahlander edited this page Jun 11, 2014
·
4 revisions
promise.finally(function callback() {
// Do stuff when promise resolves or is rejected
})
A new Promise instance that will once again resolve or reject after executing the finally-callback.
Makes it possible to execute code when Promise is resolved or rejected. Like the catch() and then() methods, this method will also return a new Promise instance. The difference is that the finally() method will not affect the state - the returned Promise will resolve or reject the same way as the original Promise. However, if an error occur in the finally() callback, then the returned Promise will reject with the exception thrown.
var db = new Dexie('db');
db.version(1).stores({friends: 'email,name'});
db.open();
// Un-remark following line to make it fail due to ConstraintError:
// db.friends.add({email: "[email protected]", name: "Oliver"});
db.friends.add({email: "[email protected]", name: "Gertrud"}).then(function() {
alert ("Successfully added friend into DB");
}).catch (function (e) {
alert ("Failed to add friend into DB: " + e);
}).finally (function() {
alert ("Finished!");
});
Dexie.js - minimalistic and bullet proof indexedDB library