Skip to content

Instantly share code, notes, and snippets.

@chaiwa-berian
Last active August 14, 2018 17:22
Show Gist options
  • Save chaiwa-berian/8168e95870f3fcd39b154ec4f1a388e4 to your computer and use it in GitHub Desktop.
Save chaiwa-berian/8168e95870f3fcd39b154ec4f1a388e4 to your computer and use it in GitHub Desktop.
//We emit done and catch start events
var util = require('util');
var Job = function Job(){
//we will use it later to pass this to a closure
var job = this;
job.process = function(){
//emulate the delay of a job async
setTimeout(function(){
job.emit('done', {completedOn: new Date()});
}, 700);
}
job.on('start',function(){
job.process();
})
}
util.inherits(Job, require('events').EventEmitter);
module.exports = Job;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment