Heartbeats

Words
105
Reading
1 min
Listen
Play
9y

Life is all about ebb and flow


I recently came across a beautiful little npm package called heartbeats.


Source

The following code is how I am currently using it.

This service handles the heartbeat of the game, and instantiates that process on startup.

var heartbeats = require('heartbeats');
var heart = heartbeats.createHeart(1000);

module.exports = {

init: function() {

    heart.createEvent(5, function(count, last){

  var globalheartage = heart.age;

  Game.update({'id':'58dc05bdd6c3d89b075f9cc9'},

{age: globalheartage}).exec(function afterwards(err, updated){

    if (err) {
  
    return err;

    } 
  });

  Game.publishUpdate('58dc05bdd6c3d89b075f9cc9', {
  age: globalheartage
  });

});

}
}

If you have any questions please feel free to drop them in the comments.

Thank you for your time and attention.


Logomakr_6m9Y20.png

Heartbeats | Ecency