Make sure the timeout is positive

This commit is contained in:
Sindre Sorhus 2017-05-14 22:03:00 +07:00
parent fd9ac502ab
commit 33c1e31d79
1 changed files with 2 additions and 2 deletions

View File

@ -8,8 +8,8 @@ class TimeoutError extends Error {
}
module.exports = (promise, ms, fallback) => new Promise((resolve, reject) => {
if (typeof ms !== 'number') {
throw new TypeError('Expected `ms` to be a number');
if (typeof ms !== 'number' && ms >= 0) {
throw new TypeError('Expected `ms` to be a positive number');
}
const timer = setTimeout(() => {