Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* Bugfix: If a call to sync or future on a wrapped object calls its c…

…allback immediately (before going async), an error occurred.
  • Loading branch information...
commit e8d5b5f16637913e31435a34466f5b10c02177f1 1 parent efad6c0
@scriby authored
Showing with 35 additions and 4 deletions.
  1. +6 −3 asyncblock.js
  2. +4 −0 changelog
  3. +1 −1  package.json
  4. +24 −0 tests/wrap.js
View
9 asyncblock.js
@@ -573,10 +573,13 @@ module.exports.wrap = function(obj){
}
args.push(function(){
- fiber = null;
- flow = null;
-
callback.apply(null, arguments);
+
+ //This is in a textTick to handle the case where an async function calls its callback immediately.
+ process.nextTick(function(){
+ fiber = null;
+ flow = null;
+ });
});
func.apply(obj, args);
View
4 changelog
@@ -1,3 +1,7 @@
+1.2.2
+
+* Bugfix: If a call to sync or future on a wrapped object calls its callback immediately (before going async), an error occurred.
+
1.2.1
* Adding caching for asyncblock.wrap calls
View
2  package.json
@@ -1,6 +1,6 @@
{
"name": "asyncblock",
- "version": "1.2.1",
+ "version": "1.2.2",
"description": "A simple and powerful abstraction of node-fibers",
"keywords": [
"fiber", "fibers", "coroutine", "stop", "go", "green", "red" ],
View
24 tests/wrap.js
@@ -91,6 +91,30 @@ suite.addBatch({
assert.deepEqual(result.first, {a: 1, b: 2, c: 3});
assert.equal(result.second, 1);
}
+ },
+
+ 'When calling a function that calls its callback immdiately': {
+ topic: function(){
+ var self = this;
+
+ var obj = {
+ test: function(callback){
+ callback(null, 1, 2, 3);
+ }
+ };
+
+ var wrapped = asyncblock.wrap(obj);
+
+ asyncblock(function(flow){
+ wrapped.sync.test();
+
+ self.callback();
+ });
+ },
+
+ 'The results are as expected': function(result){
+ //As long as no errors occur above, this test passed
+ }
}
});
Please sign in to comment.
Something went wrong with that request. Please try again.