Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
miniflycn committed Oct 1, 2013
1 parent 2d6d85a commit db0bb4f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
10 changes: 7 additions & 3 deletions lib/vaild.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ module.exports = (function () {
});
res.on('end', function () {
that.emitter.emit('end');
that.url = undefined;
that.emitter = null;
});
} else if (300 < statusCode && statusCode < 304) {
that.fetch && req.abort();
Expand Down Expand Up @@ -123,6 +121,7 @@ module.exports = (function () {
this.emitter = new EventEmitter();
this.vailds = [];
this.fetch = false;
this.finishLen = 0;
callback && this.emitter.on('check', callback);
setImmediate(function () {
that.get(urls);
Expand All @@ -136,7 +135,7 @@ module.exports = (function () {
* @param {Function} callback
*/
on: function (event, callback) {
if (event === 'data' || event === 'end') {
if (event === 'data') {
throw new Error('Do not support this event.');
}
this.emitter.on(event, callback);
Expand All @@ -156,6 +155,11 @@ module.exports = (function () {
vaild: vaild
});
});
vaild.on('end', function () {
if (++that.finishLen === that.vailds.length) {
that.emitter.emit('end');
}
});
that.vailds.push(vaild);
});
}
Expand Down
12 changes: 7 additions & 5 deletions test/vaild.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,18 @@ describe('vaild', function () {
});
});

it('should able to destroy a MutilVaild instance', function () {
it('should able to destroy a MutilVaild instance', function (done) {
var m = vaild([
'http://localhost:7777/available/0',
'http://localhost:7777/available/1',
'http://localhost:7777/available/2',
'http://localhost:7777/available/3'
]);
m.destroy();
assert.deepEqual(m.emitter, null);
assert.deepEqual(m.fetch, undefined);
]).on('end', function () {
m.destroy();
assert.deepEqual(m.emitter, null);
assert.deepEqual(m.fetch, undefined);
done();
});
});

it('should emit end event when finish validity detection', function (done) {
Expand Down

0 comments on commit db0bb4f

Please sign in to comment.