asyncLocalStorage.exit(callback[, ...args])
添加於:v13.10.0、v12.17.0
Stability: 1 - 實驗性
參數
callback
<Function>...args
<any>
在上下文之外同步運行函數並返回其返回值。在回調函數或在回調中創建的異步操作中無法訪問存儲。在回調函數中完成的任何 getStore()
調用將始終返回 undefined
。
可選的args
被傳遞給回調函數。
如果回調函數拋出錯誤,錯誤也會由exit()
拋出。堆棧跟蹤不受此調用的影響,並且重新進入上下文。
例子:
// Within a call to run
try {
asyncLocalStorage.getStore(); // Returns the store object or value
asyncLocalStorage.exit(() => {
asyncLocalStorage.getStore(); // Returns undefined
throw new Error();
});
} catch (e) {
asyncLocalStorage.getStore(); // Returns the same object or value
// The error will be caught here
}
相關用法
- Node.js AsyncLocalStorage.enterWith(store)用法及代碼示例
- Node.js AsyncLocalStorage.run(store, callback[, ...args])用法及代碼示例
- Node.js AsyncLocalStorage用法及代碼示例
- Node.js AsyncResource用法及代碼示例
- Node.js AsyncHook.enable()用法及代碼示例
- Node.js AbortController用法及代碼示例
- Node.js AbortSignal.reason用法及代碼示例
- Node.js MySQL AVG()用法及代碼示例
- Node.js ServerHttp2Stream http2stream.pushStream(headers[, options], callback)用法及代碼示例
- Node.js http2.Http2ServerRequest request.url用法及代碼示例
- Node.js request.socket用法及代碼示例
- Node.js assert.notEqual(actual, expected[, message])用法及代碼示例
- Node.js tlsSocket.authorized用法及代碼示例
- Node.js zlib.deflateRaw()用法及代碼示例
- Node.js http.IncomingMessage message.rawHeaders用法及代碼示例
- Node.js Console用法及代碼示例
- Node.js GM transparent()用法及代碼示例
- Node.js URL.protocol用法及代碼示例
- Node.js http.Agent.reuseSocket(socket, request)用法及代碼示例
- Node.js fs.filehandle.datasync()用法及代碼示例
- Node.js socket.bind()用法及代碼示例
- Node.js v8.getHeapSpaceStatistics()用法及代碼示例
- Node.js http2session.destroyed用法及代碼示例
- Node.js http.ServerResponse response.statusCode用法及代碼示例
- Node.js Buffer buf.writeBigUInt64BE(value[, offset])用法及代碼示例
注:本文由純淨天空篩選整理自nodejs.org大神的英文原創作品 AsyncLocalStorage.exit(callback[, ...args])。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。