mithril-vndb/test-utils/throttleMock.js
Pierre-Yves Gérardy 0e0ed7c45d Lint
2017-06-14 00:15:08 +02:00

27 lines
426 B
JavaScript

"use strict"
module.exports = function() {
var queue = []
return {
throttle: function(fn) {
var pending = false
return function() {
if (!pending) {
queue.push(function(){
pending = false
fn()
})
pending = true
}
}
},
fire: function() {
var tasks = queue
queue = []
tasks.forEach(function(fn) {fn()})
},
queueLength: function(){
return queue.length
}
}
}