Created
January 18, 2012 09:49
-
-
Save changtimwu/1632229 to your computer and use it in GitHub Desktop.
nodejs timer example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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