Skip to content

Instantly share code, notes, and snippets.

@jbinkleyj
Forked from cowboy/thing.js
Last active August 29, 2015 14:08
Show Gist options
  • Save jbinkleyj/9f9427ae89a6d5d1a243 to your computer and use it in GitHub Desktop.
Save jbinkleyj/9f9427ae89a6d5d1a243 to your computer and use it in GitHub Desktop.
var Q = require('q');
var util = require('util');
var EventEmitter = require('events').EventEmitter;
function MyTask() {
EventEmitter.call(this);
this._deferred = Q.defer();
this.then = this._deferred.then.bind(this._deferred); // ???
}
util.extends(MyTask, EventEmitter);
MyTask.prototype.run = function() {
this.run = function() { return this; };
// Sample code
var self = this;
setTimeout(function() {
self._deferred.resolve(123);
}, 1000);
return this;
};
exports.MyTask = MyTask;
var mt = new MyTask();
mt.on("debug", console.debug);
mt.run({}, etc).then(something);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment