From a099d0735066e9defedcfb28bf8d1e7d4d8fe341 Mon Sep 17 00:00:00 2001 From: Andy Fleming Date: Tue, 14 Jan 2020 00:26:34 -0700 Subject: [PATCH] Abstracts value check to isPromise (to make it easier to follow) --- src/index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 8e3f6f9..9702f65 100644 --- a/src/index.js +++ b/src/index.js @@ -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 @@ -53,7 +60,7 @@ function interval(func, intervalLength, options = {}) { const returnVal = func(currentIteration, stop) // Any valid Promise implementation must have a `then` method - if (!(returnVal != null && typeof returnVal.then === "function")) { + if (!isPromise(returnVal)) { rootPromiseReject(new Error('Return value of "func" must be a Promise.')) return }