當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。