Skip to content

Commit

Permalink
Merge pull request #21 from aulisius/patch-1
Browse files Browse the repository at this point in the history
Modify Promise check, Closes #20
  • Loading branch information
andyfleming authored Jan 14, 2020
2 parents 078528e + 2efc2f7 commit f19a69f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 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,9 @@ function interval(func, intervalLength, options = {}) {
setTimeout(() => {

const returnVal = func(currentIteration, stop)

if (!(returnVal instanceof Promise)) {

// Ensure that the value returned is a promise
if (!isPromise(returnVal)) {
rootPromiseReject(new Error('Return value of "func" must be a Promise.'))
return
}
Expand Down

0 comments on commit f19a69f

Please sign in to comment.