Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Merge pull request #2423 from vogdb/issue-2423
Browse files Browse the repository at this point in the history
"undefined is not an object" in `promise.finally` of promiseThrottler
  • Loading branch information
vogdb authored Nov 24, 2016
2 parents fb7996a + acb7354 commit 04be32a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions client-vendor/after-body/promise-utils/promise-throttler.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,19 @@
}
}

function isPromise(promise) {
if (!promise || !(promise instanceof Promise)) {
throw new Error('Invalid usage of promiseThrottler');
}
}

return function() {
if (!promise || !promise.isPending()) {
if (!promise) {
promise = fn.apply(this, arguments);
promise.finally(resetClosurePromise.bind(null, promise));
return promise;
if (isPromise(promise)) {
promise.finally(resetClosurePromise.bind(null, promise));
return promise;
}
}
var cancelLeading = options.cancelLeading;
if (cancelLeading) {
Expand All @@ -64,7 +72,10 @@
var leadingPromise = promise;
promise = new Promise(function(resolve) {
leadingPromise.finally(function() {
resolve(fn.apply(self, args));
var promise = fn.apply(self, args);
if (isPromise(promise)) {
resolve(promise);
}
});
});
promise.finally(resetClosurePromise.bind(null, promise));
Expand Down
2 changes: 1 addition & 1 deletion library/CM/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ var CM_App = CM_Class_Abstract.extend({
var urlBase = cm.options.urlBase;
if (0 === url.indexOf(urlSite)) {
var path = url.substr(urlBase.length);
cm.getDocument().loadPage(path);
return cm.getDocument().loadPage(path);
} else {
window.location.assign(url);
return Promise.resolve();
Expand Down

0 comments on commit 04be32a

Please sign in to comment.