Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

$q .always() Implementation #1828

Closed
MandarinConLaBarba opened this issue Jan 17, 2013 · 11 comments
Closed

$q .always() Implementation #1828

MandarinConLaBarba opened this issue Jan 17, 2013 · 11 comments

Comments

@MandarinConLaBarba
Copy link

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)
@groner
Copy link
Contributor

groner commented Jan 24, 2013

+1

The upstream q package calls this .fin()

@latentflip
Copy link
Contributor

Is this issue a duplicate of #1378, if so can we move discussion there and close this one maybe? 👍

@groner
Copy link
Contributor

groner commented Jan 29, 2013

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).

@latentflip
Copy link
Contributor

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//issues/1828#issuecomment-12860978.

@maxbates
Copy link

+1

@L42y
Copy link

L42y commented May 8, 2013

duplicate of #2424?

@MikeMcElroy
Copy link
Contributor

Does this make sense with promise chaining? promise.then(callback).always(callback).then(callback again?)

@petebacondarwin
Copy link
Contributor

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//issues/1828#issuecomment-17605575
.

@MikeMcElroy
Copy link
Contributor

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//issues/1828#issuecomment-17616548
.

@groner
Copy link
Contributor

groner commented May 8, 2013

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.

@petebacondarwin
Copy link
Contributor

@groner - yes, sorry, you are absolutely right here.

By the way this is already in: #2424 - landed in master at 6605adf

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants