Skip to content

Instantly share code, notes, and snippets.

@mainiak
Created April 16, 2013 13:59
Show Gist options
  • Save mainiak/5396108 to your computer and use it in GitHub Desktop.
Save mainiak/5396108 to your computer and use it in GitHub Desktop.
#!/usr/bin/env coffee
MAX_CALLS = 10
class Test
constructor: ->
@reset()
run1: (returnFn) ->
@count += 1
console.log 'A| count:', @count
callBack = => @run1 returnFn
if @count is MAX_CALLS
console.log returnFn
returnFn() if returnFn?
else
setImmediate callBack, returnFn
reset: ->
@count = 0
console.log '// reset - done'
run2: ->
@count += 1
console.log 'B| count:', @count
setImmediate @run2.bind(@) if @count isnt MAX_CALLS
t = new Test
t.run1 ->
t.reset()
t.run2()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment