async_hooks.triggerAsyncId()
- 返回: <number> 負責調用當前正在執行的回調的資源的 ID。
const server = net.createServer((conn) => {
// The resource that caused (or triggered) this callback to be called
// was that of the new connection. Thus the return value of triggerAsyncId()
// is the asyncId of "conn".
async_hooks.triggerAsyncId();
}).listen(port, () => {
// Even though all callbacks passed to .listen() are wrapped in a nextTick()
// the callback itself exists because the call to the server's .listen()
// was made. So the return value would be the ID of the server.
async_hooks.triggerAsyncId();
});
默認情況下,Promise 上下文可能無法獲得有效的 triggerAsyncId
。請參閱 promise execution tracking 部分。
相關用法
- Node.js AsyncHook async_hooks.executionAsyncId()用法及代碼示例
- Node.js AsyncHook async_hooks.executionAsyncResource()用法及代碼示例
- Node.js async_hooks.createHook(callbacks)用法及代碼示例
- Node.js async.queue()用法及代碼示例
- Node.js assert.notEqual(actual, expected[, message])用法及代碼示例
- Node.js assert.notDeepStrictEqual(actual, expected[, message])用法及代碼示例
- Node.js assert.fail(actual, expected[, message[, operator[, stackStartFn]]])用法及代碼示例
- Node.js assert.deepStrictEqual()用法及代碼示例
- Node.js assert.deepEqual(actual, expected[, message])用法及代碼示例
- Node.js assert.throws(fn[, error][, message])用法及代碼示例
- Node.js assert.equal()用法及代碼示例
- Node.js assert.ifError()用法及代碼示例
- Node.js assert.throws()用法及代碼示例
- Node.js assert.ok()用法及代碼示例
- Node.js assert.strictEqual()用法及代碼示例
- Node.js assert.fail()用法及代碼示例
- Node.js assert.strictEqual(actual, expected[, message])用法及代碼示例
- Node.js assert.doesNotThrow(fn[, error][, message])用法及代碼示例
- Node.js assert.notStrictEqual(actual, expected[, message])用法及代碼示例
- Node.js assert.deepStrictEqual(actual, expected[, message])用法及代碼示例
- Node.js assert.match()用法及代碼示例
- Node.js assert.notDeepStrictEqual()用法及代碼示例
- Node.js assert.doesNotThrow()用法及代碼示例
- Node.js assert.rejects()用法及代碼示例
- Node.js assert.doesNotReject(asyncFn[, error][, message])用法及代碼示例
注:本文由純淨天空篩選整理自nodejs.org大神的英文原創作品 async_hooks.triggerAsyncId()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。