-
-
Notifications
You must be signed in to change notification settings - Fork 31
Checking obj.catch #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This isn't really designed to check whether something is an instance of It lets you create fast paths for synchronous optimisation. For example, consider the following: function processSequence(seq) {
var i = 0;
function next(result) {
if (i >= seq.length) return result;
return Promise.resolve(seq[i++](result)).then(next, reject);
}
return next();
}
processSequence([
() => readFileAsync('foo.json'),
str => JSON.parse(str),
data => fetch(data.url)
]); We could use is-promise to improve the performance of that code by only recursing when we actually needed to: function processSequence(seq) {
var i = 0;
function next(result) {
if (i >= seq.length) return result;
while (i < seq.length && !isPromise(result)) {
result = seq[i++](result);
}
return Promise.resolve(result).then(next, reject);
}
return next();
}
processSequence([
() => readFileAsync('foo.json'),
str => JSON.parse(str),
data => fetch(data.url)
]); This new example won't waste time converting the result of By checking |
Just got caught up using
is-promise
with a jQuery.Deferred asthen
is defined butcatch
is not. Since this isis-promise
and notis-thenable
I figured it might be a good idea to checkcatch
as well.The text was updated successfully, but these errors were encountered: