Skip to content

Instantly share code, notes, and snippets.

@takeshy
Last active December 31, 2015 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takeshy/8024277 to your computer and use it in GitHub Desktop.
Save takeshy/8024277 to your computer and use it in GitHub Desktop.
socket.io-reqev用demo timer.js
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