-
Notifications
You must be signed in to change notification settings - Fork 29.1k
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 1 commit
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,7 @@ class Environment { | |
inline uint32_t* fields(); | ||
inline int fields_count() const; | ||
inline bool call_init_hook(); | ||
bool enabled; | ||
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. Style: at the very least, rename it to That said, I believe AsyncHooks is exposed to JS land. In that case, 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 have exposed it though 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 brought it up mostly because it looked incongruous. I'll defer to @trevnorris here. |
||
|
||
private: | ||
friend class Environment; // So we can call the constructor. | ||
|
@@ -358,6 +359,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 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.
Initialize with
: enabled_(false)
.