UNPKG

glob-watcher

Version:

Watch globs and execute a function upon change, with intelligent defaults for debouncing and queueing.

27 lines (21 loc) 370 B
'use strict'; function debounce(fn, delay) { var timeout; var args; var self; return function () { self = this; args = arguments; clear(); timeout = setTimeout(run, delay); }; function run() { clear(); fn.apply(self, args); } function clear() { clearTimeout(timeout); timeout = null; } } module.exports = debounce;