Comparing version 0.2.1 to 0.2.2
{ | ||
"name": "emoney", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"homepage": "https://github.com/elnarddogg/emoney.git", | ||
@@ -9,3 +9,3 @@ "authors": [ | ||
"description": "A lightweight event emitter for clients and servers", | ||
"main": "dist/emoney-0.2.1.min.js", | ||
"main": "dist/emoney-0.2.2.min.js", | ||
"keywords": [ | ||
@@ -12,0 +12,0 @@ "javascript", |
{ | ||
"name": "emoney", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "A lightweight event emitter for clients and servers", | ||
"main": "dist/emoney-0.2.1.min.js", | ||
"main": "dist/emoney-0.2.2.min.js", | ||
"scripts": { | ||
@@ -7,0 +7,0 @@ "test": "mocha test/test.js" |
@@ -47,8 +47,9 @@ import when from 'when'; | ||
proto.$$flush = function() { | ||
proto.$$flush = function( clear ) { | ||
var that = this; | ||
var stack = that.__stack; | ||
var task; | ||
if (that.__inprog) { | ||
if (that.__inprog && !clear) { | ||
return; | ||
@@ -60,3 +61,12 @@ } | ||
while ($_length( stack )) { | ||
$_shift( stack )(); | ||
try { | ||
task = $_shift( stack ); | ||
if (!clear) { | ||
task(); | ||
} | ||
} | ||
catch( err ) { | ||
that.$$flush( true ); | ||
throw err; | ||
} | ||
} | ||
@@ -63,0 +73,0 @@ |
@@ -90,2 +90,61 @@ (function() { | ||
describe( '$$enq' , function() { | ||
it( 'should push a task to __stack' , function( done ) { | ||
emoney.$$enq(function() { | ||
// ... | ||
}); | ||
expect( emoney.__stack.length ).to.equal( 1 ); | ||
emoney.$$flush(); | ||
done(); | ||
}); | ||
}); | ||
describe( '$$flush' , function() { | ||
it( 'should sequentially execute tasks in __stack' , function( done ) { | ||
var result = [], count = 3; | ||
for (var i = 0; i < count; i++) { | ||
(function( i ) { | ||
emoney.$$enq(function() { | ||
var index = result.length; | ||
result.push( index ); | ||
expect( result[i] ).to.equal( index ); | ||
}); | ||
}( i )); | ||
} | ||
expect( emoney.__stack.length ).to.equal( count ); | ||
emoney.$$flush(); | ||
expect( result.length ).to.equal( count ); | ||
done(); | ||
}); | ||
it( 'should clear the stack when an error is encountered' , function( done ) { | ||
var count = 5; | ||
for (var i = 0; i < count; i++) { | ||
(function( i ) { | ||
emoney.$$enq(function() { | ||
if (i < 4 && i > 1) { | ||
throw new Error( 'test error ' + i ); | ||
} | ||
}); | ||
}( i )); | ||
} | ||
expect( emoney.__stack.length ).to.equal( count ); | ||
expect(function(){ emoney.$$flush() }).to.throw( /test error 2/ ); | ||
expect( emoney.__stack.length ).to.equal( 0 ); | ||
done(); | ||
}); | ||
}); | ||
describe( '#__add' , function() { | ||
@@ -92,0 +151,0 @@ |
136880
1651