Skip to content

Commit

Permalink
avoid calling end more than once
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelog committed Aug 26, 2014
1 parent e9745e4 commit 28dc828
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Marcelo Gornstein <marcelog@gmail.com>",
"name": "minionpool",
"description": "A simple task-consumer pool for nodejs",
"version": "0.0.9",
"version": "0.0.10",
"homepage": "https://github.com/marcelog/minionpool",
"keywords": [
"worker", "pool", "task", "consumer"
Expand Down
8 changes: 6 additions & 2 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var events = require('events');

function Base(options) {
Base.super_.call(this);
this.endCalled = false;
for(k in options) {
this[k] = options[k];
}
Expand Down Expand Up @@ -68,8 +69,11 @@ Base.prototype.start = function() {
Base.prototype.end = function() {
var self = this;
this.endFunction(this.state, function() {
self.emit('ended');
self.debugMsg('Ended');
if(!self.endCalled) {
self.endCalled = true;
self.emit('ended');
self.debugMsg('Ended');
}
});
};
exports.Base = Base;

0 comments on commit 28dc828

Please sign in to comment.