@neoziro If user can use delay and timeout without external dependency it would be great.
I understand but I prefer to keep it separated, if you want to avoid additional dependencies, you can code it quickly:
const delay = ms => new Promise(resolve => setTimeout(resolve), ms)
const pTimeout = async (promise, ms) =>
Promise.race([
promise,
async () => {
await delay(ms)
throw new Error('Timeout')
},
])
const pDelay = async (promise, ms) => {
await wait(ms)
return promise
}
const DelayedComponent = loadable(pDelay(() => import('./MyComponent'), 200))
const TimeoutComponent = loadable(pTimeout(() => import('./MyComponent'), 3000))
@neoziro Thank you for your response. Should we need to handle the case of delay + timeout?
const TimeoutComponent = loadable(pDelay(pTimeout(() => import('./MyComponent'), 3000), 200))
馃槈
If you like functional programming and composition you can slightly change it.
const delay = ms => new Promise(resolve => setTimeout(resolve), ms)
const pTimeout = ms => async promise =>
Promise.race([
promise,
async () => {
await delay(ms)
throw new Error('Timeout')
},
])
const pDelay = ms => async promise => {
await wait(ms)
return promise
}
const DelayedComponent = loadable(compose(
pDelay(200),
pTimeout(200),
)(() => import('./MyComponent')))
@neoziro Thanks. It really helpful ;)
@neoziro If you can add the "timeout + delay" as a part of your README. It would be great 馃憤
Most helpful comment
馃槈
If you like functional programming and composition you can slightly change it.