-
-
Save jbinkleyj/9f9427ae89a6d5d1a243 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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