-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
async-wrap: always call before and after hooks #665
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -255,6 +255,8 @@ class Environment { | |
inline uint32_t* fields(); | ||
inline int fields_count() const; | ||
inline bool call_init_hook(); | ||
inline bool is_enabled() const; | ||
inline void set_enabled(bool enabled); | ||
|
||
private: | ||
friend class Environment; // So we can call the constructor. | ||
|
@@ -263,6 +265,9 @@ class Environment { | |
enum Fields { | ||
// Set this to not zero if the init hook should be called. | ||
kCallInitHook, | ||
// Set this to not zero if async wrap should be enabled. This is | ||
// automatically set when SetupHooks is called. | ||
kEnabled, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name of the field is confusing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. EDIT: it was confusing before because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know you know this, but to reiterate. The point was that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks for reiterating, I actually didn't realize that. The comment in (https://github.com/iojs/io.js/blob/v1.x/src/async-wrap.cc#L39) is rather confusing then:
I realize now that it also says:
which should be read as "if and only if". Sometimes I think my math education have kills all implicit human understanding :) In any case I find it a bit confusing, the I would propose having a I'm not sure how much of a performance hit a no-opt call is these days, but I guess having The logic behind preventing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I have come to the conclusion that both behaviors are reasonable. However the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. want to change the name to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. I will refactor this PR to do that and redo the tests. |
||
kFieldsCount | ||
}; | ||
|
||
|
@@ -358,6 +363,7 @@ class Environment { | |
|
||
inline v8::Isolate* isolate() const; | ||
inline uv_loop_t* event_loop() const; | ||
inline bool use_async_hook() const; | ||
inline bool call_async_init_hook() const; | ||
inline bool in_domain() const; | ||
inline uint32_t watched_providers() const; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
|
||
var asyncWrap = process.binding('async_wrap'); | ||
|
||
var asyncHooksObject = {}; | ||
var kEnabled = 1; | ||
asyncWrap.setupHooks(asyncHooksObject, init, before, after); | ||
asyncHooksObject[kEnabled] = 0; | ||
|
||
var order = []; | ||
|
||
function init() { | ||
order.push('init ' + this.constructor.name); | ||
} | ||
|
||
function before() { | ||
order.push('before ' + this.constructor.name); | ||
} | ||
|
||
function after() { | ||
order.push('after ' + this.constructor.name); | ||
} | ||
|
||
setTimeout(function () { | ||
order.push('callback'); | ||
}); | ||
|
||
process.once('exit', function () { | ||
assert.deepEqual(order, [ | ||
'callback' | ||
]); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
|
||
var asyncWrap = process.binding('async_wrap'); | ||
|
||
var asyncHooksObject = {}; | ||
var kCallInitHook = 0; | ||
asyncWrap.setupHooks(asyncHooksObject, init, before, after); | ||
asyncHooksObject[kCallInitHook] = 1; | ||
|
||
var order = []; | ||
|
||
function init() { | ||
order.push('init ' + this.constructor.name); | ||
} | ||
|
||
function before() { | ||
order.push('before ' + this.constructor.name); | ||
} | ||
|
||
function after() { | ||
order.push('after ' + this.constructor.name); | ||
} | ||
|
||
setTimeout(function () { | ||
order.push('callback'); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for a future note, this may be spotty because there's incomplete timer support. Because only a single |
||
|
||
process.once('exit', function () { | ||
assert.deepEqual(order, [ | ||
'init Timer', 'before Timer', 'callback', 'after Timer' | ||
]); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
|
||
var asyncWrap = process.binding('async_wrap'); | ||
|
||
var asyncHooksObject = {}; | ||
asyncWrap.setupHooks(asyncHooksObject, init, before, after); | ||
|
||
var order = []; | ||
|
||
function init() { | ||
order.push('init ' + this.constructor.name); | ||
} | ||
|
||
function before() { | ||
order.push('before ' + this.constructor.name); | ||
} | ||
|
||
function after() { | ||
order.push('after ' + this.constructor.name); | ||
} | ||
|
||
setTimeout(function () { | ||
order.push('callback'); | ||
}); | ||
|
||
process.once('exit', function () { | ||
assert.deepEqual(order, [ | ||
'before Timer', 'callback', 'after Timer' | ||
]); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a test added to check
kEnabled
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, can you distinguish what "JS hook functions" this means? There are 4 of them, and this doesn't affect them all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are 3 of them (
init
,pre
andpost
), right? This should affect all of them.I will add a test case then. I was just unsure about the test policy for async wrap.