Skip to content

Commit

Permalink
Merge a099d07 into 078528e
Browse files Browse the repository at this point in the history
  • Loading branch information
aulisius committed Jan 14, 2020
2 parents 078528e + a099d07 commit f5b77c6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* @param {*} val - value to check
*
* @returns {boolean} true if the value is then-able
*/
const isPromise = val => (val != null && typeof val.then === "function")

/**
* @param {function} func - function to execute
* @param {number|function(number):number} intervalLength - length in ms to wait before executing again
Expand Down Expand Up @@ -52,8 +59,8 @@ function interval(func, intervalLength, options = {}) {
setTimeout(() => {

const returnVal = func(currentIteration, stop)

if (!(returnVal instanceof Promise)) {
// Any valid Promise implementation must have a `then` method
if (!isPromise(returnVal)) {
rootPromiseReject(new Error('Return value of "func" must be a Promise.'))
return
}
Expand Down

0 comments on commit f5b77c6

Please sign in to comment.