Skip to content

Commit

Permalink
Merge pull request tildeio#62 from teddyzeenny/promise-labels
Browse files Browse the repository at this point in the history
Label all promises for debugging
  • Loading branch information
stefanpenner committed Dec 21, 2013
2 parents 73fc170 + 3adab38 commit 0a521d5
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ Transition.prototype = {
@param {Function} success
@param {Function} failure
*/
then: function(success, failure) {
return this.promise.then(success, failure);
then: function(success, failure, label) {
return this.promise.then(success, failure, label);
},

/**
Expand Down Expand Up @@ -1037,7 +1037,7 @@ function performTransition(router, recogHandlers, providedModelsArray, params, q
wasTransitioning = true;
}

var deferred = RSVP.defer(),
var deferred = RSVP.defer(promiseLabel("Transition to '" + targetName + "'")),
transition = new Transition(router, deferred.promise);

transition.targetName = targetName;
Expand All @@ -1060,7 +1060,7 @@ function performTransition(router, recogHandlers, providedModelsArray, params, q

log(router, transition.sequence, "Beginning validation for transition to " + transition.targetName);
validateEntry(transition, matchPointResults.matchPoint, matchPointResults.handlerParams)
.then(transitionSuccess, transitionFailure);
.then(transitionSuccess, transitionFailure, promiseLabel("Handle transition success / failure"));

return transition;

Expand Down Expand Up @@ -1215,7 +1215,7 @@ function validateEntry(transition, matchPoint, handlerParams) {

if (index === handlerInfos.length) {
// No more contexts to resolve.
return RSVP.resolve(transition.resolvedModels);
return RSVP.resolve(transition.resolvedModels, promiseLabel("Transition '" + transition.targetName + "' handlers complete"));
}

var router = transition.router,
Expand All @@ -1237,20 +1237,20 @@ function validateEntry(transition, matchPoint, handlerParams) {

transition.trigger(true, 'willResolveModel', transition, handler);

return RSVP.resolve().then(handleAbort)
.then(beforeModel)
.then(handleAbort)
.then(model)
.then(handleAbort)
.then(afterModel)
.then(handleAbort)
.then(null, handleError)
.then(proceed);
return RSVP.resolve(undefined, promiseLabel("Start route '" + handlerName + "'")).then(handleAbort, null, promiseLabel("Handle abort"))
.then(beforeModel, null, promiseLabel("Before model"))
.then(handleAbort, null, promiseLabel("Handle abort"))
.then(model, null, promiseLabel("Model"))
.then(handleAbort, null, promiseLabel("Handle abort"))
.then(afterModel, null, promiseLabel("After model"))
.then(handleAbort, null, promiseLabel("Handle abort"))
.then(null, handleError, promiseLabel("Handle error"))
.then(proceed, null, promiseLabel("Proceed to next handler"));

function handleAbort(result) {
if (transition.isAborted) {
log(transition.router, transition.sequence, "detected abort.");
return RSVP.reject(new Router.TransitionAborted());
return RSVP.reject(new Router.TransitionAborted(), promiseLabel("Transition aborted"));
}

return result;
Expand All @@ -1260,7 +1260,7 @@ function validateEntry(transition, matchPoint, handlerParams) {
if (reason instanceof Router.TransitionAborted || transition.isAborted) {
// if the transition was aborted and *no additional* error was thrown,
// reject with the Router.TransitionAborted instance
return RSVP.reject(reason);
return RSVP.reject(reason, promiseLabel("Transition aborted"));
}

// otherwise, we're here because of a different error
Expand All @@ -1273,7 +1273,7 @@ function validateEntry(transition, matchPoint, handlerParams) {
transition.trigger(true, 'error', reason, transition, handlerInfo.handler);

// Propagate the original error.
return RSVP.reject(reason);
return RSVP.reject(reason, promiseLabel("Transition error"));
}

function beforeModel() {
Expand Down Expand Up @@ -1445,3 +1445,12 @@ function serialize(handler, model, names) {
return object;
}

/**
@private
Wraps a promise label with
library specific identifier
*/
function promiseLabel(text) {
return "Router: " + text;
}

0 comments on commit 0a521d5

Please sign in to comment.