UNPKG

hd-utils

Version:

A handy utils for modern JS developers

22 lines (20 loc) 689 B
import networkHttpRequestMonitor from './networkHttpRequestMonitor'; /** * * @description --Browser only -- a function that takes callback to be executed when the network becomes idle, which means no active network requests (like XHR or Fetch API) are ongoing. * @example * `// Usage const cancel = setNetworkIdleCallback(() => { console.log('Network is now idle.'); }); // to cancel cancel();` */ export default function setNetworkIdleCallback(callback, options) { if (!callback) throw new Error('setNetworkIdleCallback Callback is undefined'); return networkHttpRequestMonitor(callback, undefined, { ...options, cancelAfterIdle: true, }); }