Skip to content

Commit

Permalink
2.1.6
Browse files Browse the repository at this point in the history
Allow the current asyncblock's flow to be gotten from a function called from the current fiber.
  • Loading branch information
scriby committed Oct 4, 2012
1 parent 86adc82 commit c01d14c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
28 changes: 28 additions & 0 deletions changelog
@@ -1,3 +1,31 @@
2.1.6

* Allow the current asyncblock's flow to be gotten from a function called from the current fiber.

2.1.5

* Allow asyncblock transform compilation to be kicked off independently. This allows a build process or otherwise to run the transformations beforehand.

2.1.4

* Fix an instance of errors getting swallowed within nested asyncblocks.

2.1.3

* Allow 2nd arg to be specified to an asyncblock, which acts as the return handler.

2.1.2

* Fix an issue with deferred variables not getting handled correctly if assigned to an object property

2.1.1

* Fix issue with asyncblock not working with Coffeescript

2.1.0

* Update to fibers v0.6.8 for node v0.8 support.

2.0.9 2.0.9


* x().sync() optimization - Reuse the fiber from the outer asyncblock in the inner asyncblock. Lower overhead and same behavior. * x().sync() optimization - Reuse the fiber from the outer asyncblock in the inner asyncblock. Lower overhead and same behavior.
Expand Down
12 changes: 11 additions & 1 deletion lib/asyncblock.js
Expand Up @@ -109,7 +109,7 @@ var asyncblock = function(fn, done, options) {
}; };


module.exports = function(fn, done, options){ module.exports = function(fn, done, options){
//Capture stack trace by defaultrequire('./lib/transform.js'); //Capture stack trace by default
var err = new Error(); var err = new Error();
//Currently not capturing stack trace as it's about 60% slower than just making the error (and just takes 1 frame off stack trace) //Currently not capturing stack trace as it's about 60% slower than just making the error (and just takes 1 frame off stack trace)
//Error.captureStackTrace(err, module.exports); //Error.captureStackTrace(err, module.exports);
Expand Down Expand Up @@ -147,3 +147,13 @@ module.exports.fullstack = module.exports;
module.exports.nostack = function(fn, done){ module.exports.nostack = function(fn, done){
asyncblock(fn, done); asyncblock(fn, done);
}; };

module.exports.getCurrentFlow = function(){
var currFiber = Fiber.current;
if(currFiber){
var currFlow = currFiber._asyncblock_flow;
currFiber = null;

return currFlow;
}
};
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{ {
"name": "asyncblock", "name": "asyncblock",
"version": "2.1.5", "version": "2.1.6",
"description": "A simple and powerful abstraction of node-fibers", "description": "A simple and powerful abstraction of node-fibers",
"keywords": [ "keywords": [
"fiber", "fibers", "coroutine", "stop", "go", "green", "red" ], "fiber", "fibers", "coroutine", "stop", "go", "green", "red" ],
Expand Down
19 changes: 19 additions & 0 deletions tests/functionality.js
Expand Up @@ -1048,6 +1048,25 @@ suite.addBatch({
'The results are as expected': function(err, result){ 'The results are as expected': function(err, result){
assert.equal(err.message, 'Error'); assert.equal(err.message, 'Error');
} }
},

'When using asyncblock.currentFlow': {
topic: function(){
var testCurrent = function(){
var flow = asyncblock.getCurrentFlow();

echo('test', flow.add());
return flow.wait();
};

asyncblock(function(){
return testCurrent();
}, this.callback);
},

'Ok': function(result){
assert.equal(result, 'test');
}
} }
}); });


Expand Down

0 comments on commit c01d14c

Please sign in to comment.