当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript domain.create函数代码示例

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


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

示例1: test

  test('concurrent domain hubs', done => {
    const d1 = domain.create();
    const d2 = domain.create();
    let d1done = false;
    let d2done = false;

    d1.run(() => {
      const hub = getCurrentHub();
      hub.getStack().push({ client: 'process' });
      expect(hub.getStack()[1]).toEqual({ client: 'process' });
      // Just in case so we don't have to worry which one finishes first
      // (although it always should be d2)
      setTimeout(() => {
        d1done = true;
        if (d2done) {
          done();
        }
      });
    });

    d2.run(() => {
      const hub = getCurrentHub();
      hub.getStack().push({ client: 'local' });
      expect(hub.getStack()[1]).toEqual({ client: 'local' });
      setTimeout(() => {
        d2done = true;
        if (d1done) {
          done();
        }
      });
    });
  });
开发者ID:getsentry,项目名称:raven-js,代码行数:32,代码来源:domain.test.ts

示例2: sentryRequestMiddleware

 return function sentryRequestMiddleware(
   req: http.IncomingMessage,
   res: http.ServerResponse,
   next: (error?: any) => void,
 ): void {
   if (options && options.flushTimeout && options.flushTimeout > 0) {
     // tslint:disable-next-line: no-unbound-method
     const _end = res.end;
     res.end = function(chunk?: any | (() => void), encoding?: string | (() => void), cb?: () => void): void {
       flush(options.flushTimeout)
         .then(() => {
           _end.call(this, chunk, encoding, cb);
         })
         .catch(e => {
           logger.error(e);
         });
     };
   }
   const local = domain.create();
   local.add(req);
   local.add(res);
   local.on('error', next);
   local.run(() => {
     getCurrentHub().configureScope(scope =>
       scope.addEventProcessor((event: Event) => parseRequest(event, req, options)),
     );
     next();
   });
 };
开发者ID:getsentry,项目名称:raven-js,代码行数:29,代码来源:handlers.ts

示例3: _postRequest

  /**
   * Posts a request to the Akismet API server.
   */
  private _postRequest(hostname: string, path: string,
    query: { [key: string]: any }, callback: PostRequestCallback): void {

    const requestUrl = formatURL({
      protocol: this._port === 443 ? "https" : "http",
      hostname: hostname,
      pathname: path,
      port: this._port
    });

    const options = {
      "url": requestUrl,
      "form": query,
      "headers": {
        "content-type": "charset=" + this._charSet,
        "user-agent": this._userAgent
      }
    };

    const dom = createDomain();
    dom.on("error", (err) => callback(err, 0, ""));

    dom.run(() => {
      postRequest(options, (err: any, response: Response, body: any) => {
        if (err) {
          callback(err, 0, "");
        } else {
          callback(null, response.statusCode, body);
        }
      });
    });
  }
开发者ID:oozcitak,项目名称:akismet-js,代码行数:35,代码来源:index.ts

示例4: runInContextMiddleware

    return function runInContextMiddleware(req, res, next) {
        // We want multiple request-context consumers to use the same domain
        // context object rather than creating a bunch of nested domains.
        // Their namespaces should be sufficient to keep each consumer's
        // data separate from the others.
        if (domain.active && domain.active.__$cntxt__) {
            setContext(namespace, Object.create(null), domain.active);
            next();
            return;
        }

        var d = domain.create();
        d.add(req);
        d.add(res);
        d.on('error', handleError);

        setContext(namespace, Object.create(null), d);

        d.run(next);

        function handleError(err) {
            res.setHeader('Connection', 'close');
            next(err);
        }
    };
开发者ID:Vinod0511,项目名称:Node-Data,代码行数:25,代码来源:domain.ts

示例5: function

 socket.on(namespace + '.' + methodName, function(opts){
   var d = domain.create();
   d.on('error', function(err){
     log.error('error while making command', methodName, namespace, opts);
   })
   d.run(function(){
     var inStream = createInSocketStream(socket, opts._uid);
     var outStream = createOutSocketStream(socket, opts._uid);
     var infoHandler = createInfoSocketHandler(socket, opts._info_uid);
     var commandStream = api[namespace][methodName](opts, infoHandler);
     inStream.pipe(commandStream).pipe(outStream);
     if(opts.initialData !== undefined){
       inStream.write(opts.initialData);
     }
   })
 })
开发者ID:jhliberty,项目名称:topsoil,代码行数:16,代码来源:processManager.ts

示例6: function

app.post('/', (req, res) => {
	var d = domain.create();
	var responseHasBeenSent = false;
	d.on('error', function(er) {
		if (!responseHasBeenSent) {
			responseHasBeenSent = true;
			console.log(er);
			res.status(500).send(er);
		}
	});
	d.run(function() {
		var start = Date.now();
		fileFetcher.fetchFiles(req.body.file, (allFiles: string[]) => {
			console.log('request took ' + (Date.now() - start) + ' ms to complete');
			res.status(200).send(allFiles);
		});
	});
});
开发者ID:nfriend,项目名称:ldraw-visualizer,代码行数:18,代码来源:parts-server.ts

示例7: test

    test('capture an event in a domain', done => {
      const d = domain.create();

      const client = new NodeClient({
        beforeSend: (event: Event) => {
          expect(event.message).toBe('test domain');
          expect(event.exception).toBeUndefined();
          done();
          return null;
        },
        dsn,
      });

      d.run(() => {
        getCurrentHub().bindClient(client);
        expect(getCurrentHub().getClient()).toBe(client);
        getCurrentHub().captureEvent({ message: 'test domain' });
      });
    });
开发者ID:getsentry,项目名称:raven-js,代码行数:19,代码来源:index.test.ts


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