Skip to content
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

Modify Promise check, Closes #20 #21

Merged
merged 3 commits into from
Jan 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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