$q .always() Implementation
I know the goal is to keep $q lightweight, but any interest in an 'always' callback facility? Either an additional arg in .then()
.then(successCallback, errorCallback, alwaysCallback)
Or something like:
.then(callback).always(callback)
+1
The upstream q package calls this .fin()
Is this issue a duplicate of #1378, if so can we move discussion there and close this one maybe? :+1:
They're different. The .fin() method is supposed to be like a finally block. The .end() method is a mechanism to say I'm done with this, if I missed something please treat it as an unhandled exception (log it, use $exceptionHandler, incite a riot).
Oops, my bad. As you were :) On 29 Jan 2013 22:04, "Kai Groner" [email protected] wrote:
They're different. The .fin() method is supposed to be like a finally block. The .end() method is a mechanism to say I'm done with this, if I missed something please treat it as an unhandled exception (log it, use $exceptionHandler, incite a riot).
— Reply to this email directly or view it on GitHubhttps://github.com/angular/angular.js/issues/1828#issuecomment-12860978.
+1
duplicate of #2424?
Does this make sense with promise chaining? promise.then(callback).always(callback).then(callback again?)
Yes. It is semantically equivalent to simply providing the same handler for both parameters of the then() function.
Pete ...from my mobile. On May 8, 2013 2:32 PM, "MikeMcElroy" [email protected] wrote:
Does this make sense with promise chaining? promise.then(callback).always(callback).then(callback again?)
— Reply to this email directly or view it on GitHubhttps://github.com/angular/angular.js/issues/1828#issuecomment-17605575 .
Provided that callback has no dependencies on what information it receives, or the resolved promise passed the same information as the rejected promise?
On Wed, May 8, 2013 at 9:16 AM, Pete Bacon Darwin [email protected]:
Yes. It is semantically equivalent to simply providing the same handler for both parameters of the then() function.
Pete ...from my mobile. On May 8, 2013 2:32 PM, "MikeMcElroy" [email protected] wrote:
Does this make sense with promise chaining? promise.then(callback).always(callback).then(callback again?)
— Reply to this email directly or view it on GitHub< https://github.com/angular/angular.js/issues/1828#issuecomment-17605575> .
— Reply to this email directly or view it on GitHubhttps://github.com/angular/angular.js/issues/1828#issuecomment-17616548 .
An always/finally callback receives no arguments and it resolves to same as the original promise unless it rejects.
// Resolves to 5
$q.when(5).always(function() { return 7 });
// Resolves to 5 after 1 second
$q.when(5).always(q.delay(1000) { return 7 });
// Rejects with Error: nowayjose
$q.when(5).always(function() { throw new Error('nowayjose') });
See https://github.com/kriskowal/q/wiki/API-Reference#promisefinallycallback.
@groner - yes, sorry, you are absolutely right here.
By the way this is already in: https://github.com/angular/angular.js/pull/2424 - landed in master at https://github.com/angular/angular.js/commit/6605adf