创建异步上下文容器
const asyncContext = require('node-async-context')
process.context = asyncContext.create()
设置当前异步上下文的值
process.context.set('demoKey', 'demoValue')
获取当前异步上下文的值
const value = process.context.get('demoKey')
删除当前异步上下文的值
process.context.del('demoKey')
销毁当前异步上下文
process.context.destroy()
获取当前异步上下文
const ah = require('async_hooks')
const asyncId = ah.executionAsyncId()
const currentContext = process.context.getByAsyncId(asyncId)
设置当前异步上下文
const ah = require('async_hooks')
const asyncId = ah.executionAsyncId()
process.context.setByAsyncId(asyncId, { demoKey: 'demoValue' })
销毁当前异步上下文
const ah = require('async_hooks')
const asyncId = ah.executionAsyncId()
process.context.destroyByAsyncId(asyncId)
运行一个新的异步上下文
const express = require('express')
const app = express()
app.use((req, res, next) => {
process.context.run(next)
})