We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
const delayed1 = pMinDelay(fn, 1000) const delayed2 = pMinDelay(fn, 1000, {delayRejection: false})
delayed1() takes at least 1s to settle. delayed2() takes at least 1s to resolve.
delayed1()
delayed2()
I have similar function in my recent project accepts both Promise and function, I called it slowDown.
slowDown
The text was updated successfully, but these errors were encountered:
It's unclear to me what problem accepting a function would solve and how it would handle the function?
Sorry, something went wrong.
what problem accepting a function would solve
Before:
const foo = async () => {} const bar = await pMinDelay(foo())
After
const foo = pMinDelay(async () => {}) const bar = await foo()
how it would handle the function?
My implemention
async function slowDownPromise(promise, time) { const [result] = await Promise.all([promise, delay(time)]) return result } function slowDownFunction(fn, time) { return function (...args) { return slowDownPromise(fn.apply(this, args), time) } } function slowDown(promiseOrFunction, time) { return ( typeof promiseOrFunction === 'function' ? slowDownFunction : slowDownPromise )(promiseOrFunction, time) }
Ah. That's a good idea. 👍
No branches or pull requests
delayed1()
takes at least 1s to settle.delayed2()
takes at least 1s to resolve.I have similar function in my recent project accepts both Promise and function, I called it
slowDown
.The text was updated successfully, but these errors were encountered: