Skip to content

Instantly share code, notes, and snippets.

@5509
Created February 23, 2012 13:27
Show Gist options
  • Save 5509/1892781 to your computer and use it in GitHub Desktop.
Save 5509/1892781 to your computer and use it in GitHub Desktop.
Repeat func
# Repeat func
#
# @param {}
# {
# interval: 50,
# func: ->
# console.log 'func'
# }
#
# or
#
# {
# interval: 50,
# func: {
# key1: ->
# console.log 'key1'
# key2: ->
# console.log 'key2'
# .
# .
# .
# }
# }
utils.repeat = class Repeat
constructor: (conf) ->
if !(@ instanceof Repeat)
return new Repeat(conf)
return @init(conf)
init: (conf) ->
@disable = no
@running = no
@conf =
interval: 50,
func: ->
for c of conf
@conf[c] = conf[c]
return
run: (func_key) ->
@disable = no
@running = yes
conf = @conf
do =>
if @disable
return
if typeof conf.func is 'function'
conf.func()
else if typeof conf.func is 'object'
conf.func[func_key]()
setTimeout(arguments.callee, conf.interval)
return
return
stop: ->
@disable = yes
@running = no
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment