-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
async_hooks,doc: some async_hooks improvements
Update docs and type checking for AsyncResource type PR-URL: #15103 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
- Loading branch information
Showing
5 changed files
with
128 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
test/async-hooks/test-embedder.api.async-resource-no-type.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const async_hooks = require('async_hooks'); | ||
const { AsyncResource } = async_hooks; | ||
const { spawn } = require('child_process'); | ||
|
||
const initHooks = require('./init-hooks'); | ||
|
||
if (process.argv[2] === 'child') { | ||
initHooks().enable(); | ||
|
||
class Foo extends AsyncResource { | ||
constructor(type) { | ||
super(type, async_hooks.executionAsyncId()); | ||
} | ||
} | ||
|
||
[null, undefined, 1, Date, {}, []].forEach((i) => { | ||
common.expectsError(() => new Foo(i), { | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
type: TypeError | ||
}); | ||
}); | ||
|
||
} else { | ||
const args = process.argv.slice(1).concat('child'); | ||
spawn(process.execPath, args) | ||
.on('close', common.mustCall((code) => { | ||
// No error because the type was defaulted | ||
assert.strictEqual(code, 0); | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters