Skip to content

Instantly share code, notes, and snippets.

@changtimwu
Created January 18, 2012 09:49
Show Gist options
  • Select an option

  • Save changtimwu/1632229 to your computer and use it in GitHub Desktop.

Select an option

Save changtimwu/1632229 to your computer and use it in GitHub Desktop.
nodejs timer example
#usage:
#coffee timer.coffee
#input the following command
# s1000
# e
# s100
# e
# s2000
# e
cbfunc = (x) ->
console.log 'got timer'
process.stdin.resume()
process.stdin.setEncoding 'utf8'
gti=0
process.stdin.on 'data', (chunk) ->
dstr = chunk.toString().trim()
[cmd,arg]= [dstr[0], dstr[1..]]
switch cmd
when 't'
console.log 'data: ' + dstr
when 's'
gti = setInterval cbfunc, parseInt(arg)
when 'e'
clearInterval gti
when 'q'
break
else
console.log 'you input ',dstr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment