shell-ahk
Version:
`Lodash`/`jQuery` for `AHK`.
24 lines (17 loc) • 526 B
text/coffeescript
# @ts-check
import $clearTimeout from './clearTimeout'
import $now from './now'
import $setTimeout from './setTimeout'
$iThrottle = 0
$tThrottle = {}
$tsThrottle = {}
###* @type import('../type/module').Throttle ###
export default ($func, $wait) ->
$iThrottle++
$tsThrottle[$iThrottle] = 0
return ($index = $iThrottle) ->
$clearTimeout $tThrottle[$index]
$tThrottle[$index] = $setTimeout ->
$func()
$tsThrottle[$index] = $now()
, $tsThrottle[$index] - $now() + $wait