/Promise.prototype.finally

This package has been superseded by https://github.com/es-shims/Promise.prototype.finally as of v2.0.0. Please upgrade!

Primary LanguageJavaScript

Promise.prototype.finally Codeship Status for matthew-andrews/Promise.prototype.finally

Note

This package has been superseded by https://github.com/es-shims/Promise.prototype.finally as of v2.0.0. Please upgrade!


A polyfill for Promise.prototype.finally. See docs on what finally is on your favourite pre-ES6 promise library.

Warning: This micro-library doesn't force you to use any particular Promise implementation by using whatever Promise has been defined as globally. This is so that you may use any ES6 standard Promise compliant library - or, of course, native ES6 Promises.

If you're running the code on a browser or node version that doesn't include native promises you will need to include a polyfill. The following polyfills are tested as part of this module's test suite:-

Installation

npm install promise.prototype.finally --save

Examples

require('es6-promise').polyfill();
require('promise.prototype.finally');

Promise.resolve(6)
	.finally(function() {
		console.log('this will always be called');
	});

Promise.reject(6)
	.finally(function() {
		console.log('this will always be called');
	});

Credits and collaboration

The lead developer of Promise.prototype.finally is Matt Andrews at FT, the code is based on a snippet by Stefan Penner - used with permission. All open source code released by FT Labs is licenced under the MIT licence. We welcome comments, feedback and suggestions. Please feel free to raise an issue or pull request.