Permalink
Browse files

Fix bug where error would not be emitted

  • Loading branch information...
1 parent a3e6776 commit 0a02c7842ff4cdf4c0a2bd8518e7653cfc943dde @ritch ritch committed Apr 19, 2013
Showing with 33 additions and 5 deletions.
  1. +22 −0 example/hello-world.js
  2. +5 −2 lib/task-emitter.js
  3. +5 −3 lib/task.js
  4. +1 −0 package.json
View
@@ -0,0 +1,22 @@
+var TaskEmitter = require('../');
+var fs = require('fs');
+var path = require('path');
+
+var te = new TaskEmitter();
+
+te
+ .on('readdir', function (dir, files) {
+ files.forEach(function (file) {
+ te.task(fs, 'stat', path.join(dir, file));
+ });
+ })
+ .on('stat', function (file, stat) {
+ console.log(file, stat);
+ })
+ .once('error', function (err) {
+ console.log('error', err);
+ })
+ .once('done', function () {
+ console.log('done.');
+ })
+ .task(fs, 'readdir', './sample-fools');
View
@@ -85,8 +85,11 @@ TaskEmitter.prototype.task = function (name, fn) {
}.bind(this));
}.bind(this));
- task.once('error', function () {
- this.errored = true;
+ task.once('error', function (err) {
+ // stop all pending tasks
+ this.stop();
+ // emit the error
+ this.emit('error', err);
}.bind(this));
tasks.push(task);
View
@@ -107,7 +107,9 @@ Task.prototype.stop = function () {
*/
Task.prototype.cleanup = function () {
- delete this.options.fn;
- delete this.options.scope;
- delete this.options;
+ if(this.options) {
+ delete this.options.fn;
+ delete this.options.scope;
+ delete this.options;
+ }
}
View
@@ -1,5 +1,6 @@
{
"name": "task-emitter",
+ "author": "Ritchie Martori",
"description": "task-emitter",
"version": "0.0.1",
"scripts": {

0 comments on commit 0a02c78

Please sign in to comment.