UNPKG

idle-until-urgent

Version:

Defer JS work until the browser has a chance to breathe

22 lines (15 loc) 275 B
const idleish = require('./idleish.js') const UNLOADED = {} module.exports = workFn => { let result = UNLOADED const clear = idleish(() => { result = workFn() }) return () => { if (result === UNLOADED) { result = workFn() clear() } return result } }