title: node.js socket.io timers - singleton pattern?
body: <p>I'm using node.js and socket.io to display countdown timers.  The timers are being run on node.js and emitting the times to the client via socket.io, the times are using setTimeout.</p>
  
  <p>The problem is that with each connection, I'm instantiating a new prototype class that is getting the times and emitting the timers, however the times should be the same for every user.  Ideally, I would use io.sockets.emit (as oppose to using the 'socket' callback).  Then the times would be emitted to all clients (which is the desired behavior).</p>
  
  <p>Right now, this would cause the timers to go nuts, since theres a new object for every client that connects.</p>
  
  <p>In JavaScript, would a singleton pattern be the solution to this?</p>
  
  <p>I've tried to use this, but didn't seem to work:</p>
  
  <pre><code>var Auction = function() {
  
      Auction.instance = null;
  
      if(!Auction.instance) {
          Auction.instance = this;
      } else {
          console.log('instance');
          return Auction.instance;
      }
  
  }
  
  Auction.prototype = {
  
      init: function() {
          //setTimeout is defined here, along with a lot of other stuff
      };
  
  }
  </code></pre>
  
  <p>I'm calling it doing:</p>
  
  <pre><code>var auction = new Auction;
  auction.init();
  </code></pre>
  
  <p>This still creates the object multiple times.</p>
  
  <p>Any suggestions would be great! Thank you.</p>