• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript continuation-local-storage.createNamespace函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中continuation-local-storage.createNamespace函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createNamespace函数的具体用法?TypeScript createNamespace怎么用?TypeScript createNamespace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了createNamespace函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: function

  t.test("handler added but no listeners registered", function (t) {
    t.plan(3);

    var http = require('http')
      , n  = cls.createNamespace('no_listener')
      ;

    // only fails on Node < 0.10
    var server = http.createServer(function (req: any, res: any) {
      n.bindEmitter(req);

      t.doesNotThrow(function () {
        req.emit('event');
      });

      res.writeHead(200, {"Content-Length" : 4});
      res.end('WORD');
    });
    server.listen(8080);

    http.get('http://localhost:8080/', function (res: any) {
      t.equal(res.statusCode, 200, "request came back OK");

      res.setEncoding('ascii');
      res.on('data', function (body: any) {
        t.equal(body, 'WORD');

        server.close();
        cls.destroyNamespace('no_listener');
      });
    });
  });
开发者ID:ArtemZag,项目名称:DefinitelyTyped,代码行数:32,代码来源:continuation-local-storage-tests.ts


示例2: test

test("simple tracer built on contexts", function (t) {
  var tracer = cls.createNamespace('tracer');

  class Trace {
    harvester: any;
    constructor(harvester: any) {
      this.harvester = harvester;
    }
    runHandler(callback: any) {
      var wrapped = tracer.bind(function () {
        callback();
        this.harvester.emit('finished', tracer.get('transaction'));
      }.bind(this));
      wrapped();
    }
  }

  t.plan(6);

  var harvester = new EventEmitter();
  var trace = new Trace(harvester);

  harvester.on('finished', function (transaction: any) {
    t.ok(transaction, "transaction should have been passed in");
    t.equal(transaction.status, 'ok', "transaction should have finished OK");
    // t.equal(Object.keys(process.namespaces).length, 1, "Should only have one namespace.");
  });

  trace.runHandler(function inScope() {
    t.ok(tracer.active, "tracer should have an active context");
    tracer.set('transaction', {status : 'ok'});
    t.ok(tracer.get('transaction'), "can retrieve newly-set value");
    t.equal(tracer.get('transaction').status, 'ok', "value should be correct");
  });
});
开发者ID:ArtemZag,项目名称:DefinitelyTyped,代码行数:35,代码来源:continuation-local-storage-tests.ts


示例3: constructor

  constructor() {
    this._basename = path.basename(module.filename);
    let dbConfig = configs.getDatabaseConfig();

    if (dbConfig.logging) {
      dbConfig.logging = logger.info;
    }

    (SequelizeStatic as any).cls = cls.createNamespace("sequelize-transaction");
    this._sequelize = new SequelizeStatic(dbConfig.database, dbConfig.username,
      dbConfig.password, dbConfig);
    this._models = ({} as any);

    fs.readdirSync(__dirname).filter((file: string) => {
      return (file !== this._basename) && (file !== "interfaces");
    }).forEach((file: string) => {
      let model = this._sequelize.import(path.join(__dirname, file));
      this._models[(model as any).name] = model;
    });

    Object.keys(this._models).forEach((modelName: string) => {
      if (typeof this._models[modelName].associate === "function") {
        this._models[modelName].associate(this._models);
      }
    });
  }
开发者ID:natarajanmca11,项目名称:sequelize-typescript-examples,代码行数:26,代码来源:index.ts


示例4: initilize

 export function initilize(publisher: string, name: string, version: string, aiKey: string): void {
     if (reporter) {
         throw new Error("TelemetryReporter already initilized.");
     }
     if (aiKey) {
         reporter = new TelemetryReporter(`${publisher}.${name}`, version, aiKey);
         report(EventType.ACTIVATION);
     }
     if (!sessionNamespace) {
         sessionNamespace = createNamespace("sessionNamespace");
     }
 }
开发者ID:Manu-sh,项目名称:dotfiles,代码行数:12,代码来源:TelemetryWrapper.ts


示例5: require

const token = options.token;
if (!token) {
  console.log('トークンが指定されていません' + parser.getUsage());
  process.exit(1);
}

const databaseUrl: string = options['database-url'];
if (!databaseUrl) {
  console.log('--database-urlが指定されていません' + parser.getUsage());
  process.exit(1);
}

// Sequelizeのトランザクションを、全てのクエリで自動的に利用する設定
// http://docs.sequelizejs.com/en/latest/docs/transactions/#automatically-pass-transactions-to-all-queries
const cls = require('continuation-local-storage');
Sequelize.cls = cls.createNamespace('hx');

const botkit = require('botkit');

const controller = botkit.slackbot({
  debug: false
});

const bot = controller.spawn({
  token,
  incoming_webhook: {
    url: 'https://hooks.slack.com/services/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'
  }
})
  .startRTM(function(err: any): void {
    if (err) {
开发者ID:hxjp,项目名称:simekiri-bot,代码行数:31,代码来源:bot.ts


示例6: get

export function get(): Toe {
    let ns = retrieve(NS) || create(NS);
    let toe = option(ns.get(LABEL))
        .get_or_else(new Toe(nonce()));

    ns.run(() => ns.set(LABEL, toe));
    return toe.clone();
}
开发者ID:consumr-project,项目名称:cp,代码行数:8,代码来源:toe.ts


示例7: initialize

export function initialize(session: string, tick: Function): void {
    let ns = retrieve(NS) || create(NS);

    let toe = new Toe(part(session, KEY_SESSION))
        .for_request(nonce());

    ns.run(() => {
        ns.set(LABEL, toe);
        tick(null, toe.clone());
    });
}
开发者ID:consumr-project,项目名称:cp,代码行数:11,代码来源:toe.ts



注:本文中的continuation-local-storage.createNamespace函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript continuation-local-storage.destroyNamespace函数代码示例发布时间:2022-05-25
下一篇:
TypeScript context.Context类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap