Last active
December 31, 2015 17:59
-
-
Save takeshy/8024277 to your computer and use it in GitHub Desktop.
socket.io-reqev用demo timer.js
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
var events = require('events'); | |
var Timer = function(){ | |
this.events = ["five","ten","thirty"]; | |
var that = this; | |
setInterval(function (){ | |
var now = new Date(); | |
if(now.getSeconds() % 5 == 0){ | |
that.emit("five", {time: now.toString()}); | |
} | |
if(now.getSeconds() % 10 == 0){ | |
that.emit("ten", {time: now.toString()}); | |
} | |
if(now.getSeconds() % 30 == 0){ | |
that.emit("thirty", {time: now.toString()}); | |
} | |
},1000); | |
return this; | |
} | |
Timer.prototype = new events.EventEmitter(); | |
Timer.prototype.request = function(req,cb){ | |
if(req=="current"){ | |
cb(null,{time: new Date().toString()}); | |
} | |
} | |
module.exports = Timer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment