當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript async_hooks.executionAsyncId函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。