artdaq_node_server  v1_00_09
 All Classes Namespaces Files Variables Pages
throttle.js
1 var debounce = require('./debounce'),
2  isObject = require('./isObject');
3 
5 var FUNC_ERROR_TEXT = 'Expected a function';
6 
51 function throttle(func, wait, options) {
52  var leading = true,
53  trailing = true;
54 
55  if (typeof func != 'function') {
56  throw new TypeError(FUNC_ERROR_TEXT);
57  }
58  if (isObject(options)) {
59  leading = 'leading' in options ? !!options.leading : leading;
60  trailing = 'trailing' in options ? !!options.trailing : trailing;
61  }
62  return debounce(func, wait, {
63  'leading': leading,
64  'maxWait': wait,
65  'trailing': trailing
66  });
67 }
68 
69 module.exports = throttle;