本文整理汇总了TypeScript中async_hooks.executionAsyncId函数的典型用法代码示例。如果您正苦于以下问题:TypeScript executionAsyncId函数的具体用法?TypeScript executionAsyncId怎么用?TypeScript executionAsyncId使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了executionAsyncId函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: setRootContext
setRootContext(key, value) {
log('set:', key, value);
const rootId = async_hooks.executionAsyncId();
if (this.rootMap.has(rootId)) {
const obj = this.rootMap.get(rootId);
this.rootMap.set(rootId, Object.assign({}, obj, {[key]: value}));
} else {
this.rootMap.set(rootId, {[key]: value});
}
log(this.rootMap);
}
开发者ID:hufeng,项目名称:node-jsonrpc-dubbo,代码行数:13,代码来源:index.ts
示例2: get
/**
* 获取zonecontext值策略:
* 1. 找出当前async-resource 有context的async-resources集合;
* 2. 按就近原则, 遍历async-resources集合对应的context;
* 3. 如果context包含key值则返回,如果不包含key值,则继续;
*
* @param key
* @returns {any}
*/
get(key: string): any | undefined {
let asyncId = async_hooks.executionAsyncId();
let ids = this.getRootAsyncIdLinks(asyncId);
let value = undefined;
for (let i = 0, iLen = ids.length; i < iLen; i++) {
let contextMap = this.rootMap.get(ids[i]);
if (contextMap[key]) {
value = contextMap[key];
break;
}
}
log(`current currentAsyncId ${asyncId} value:${JSON.stringify(value)}`);
return value;
}
开发者ID:hufeng,项目名称:node-jsonrpc-dubbo,代码行数:25,代码来源:index.ts
示例3: init
////////////////////////////////////////////////////
{
const hooks: async_hooks.HookCallbacks = {
init() {},
before() {},
after() {},
destroy() {},
promiseResolve() {},
};
const asyncHook = async_hooks.createHook(hooks);
asyncHook.enable().disable().enable();
const tId: number = async_hooks.triggerAsyncId();
const eId: number = async_hooks.executionAsyncId();
class TestResource extends async_hooks.AsyncResource {
constructor() {
super('TEST_RESOURCE');
}
}
class AnotherTestResource extends async_hooks.AsyncResource {
constructor() {
super('TEST_RESOURCE', 42);
const aId: number = this.asyncId();
const tId: number = this.triggerAsyncId();
}
run() {
this.runInAsyncScope(() => {});
开发者ID:Lavoaster,项目名称:DefinitelyTyped,代码行数:31,代码来源:node-tests.ts
示例4: function
transport: function (data) {
const asyncId = async_hooks.executionAsyncId()
console.log(asyncId, data.output)
}
开发者ID:myfjdthink,项目名称:CodeNode,代码行数:4,代码来源:App.ts
注:本文中的async_hooks.executionAsyncId函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论