infinite-scroll-svelte
Version:
Wrapper that fires events when the user has scrolled it to the beginning or end
14 lines (13 loc) • 551 B
JavaScript
import { ONE_SECOND } from './constants.js';
export const genRandomId = () => Math.round(Math.random() * 10_000).toString();
export const promiseWithRejectTimeout = (fn, timeoutFailInSecs) => {
return new Promise((res, rej) => {
const finalTimeout = timeoutFailInSecs * ONE_SECOND;
const timer = setTimeout(() => {
rej(new Error(`Promise timed out after ${timeoutFailInSecs} second(s).\n${fn}`));
}, finalTimeout);
fn()
.then(res)
.finally(() => clearTimeout(timer));
});
};