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


TypeScript zeromq.socket函數代碼示例

本文整理匯總了TypeScript中zeromq.socket函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript socket函數的具體用法?TypeScript socket怎麽用?TypeScript socket使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了socket函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: test

  test('invalid config', async () => {
    const config = {
      analytics: {
        enabled: true,
        plugin: '../src/__tests__/DummyPlugin.ts',
        initHistory: { minutes: 3 }
      }
    };
    const configServer = new ConfigResponder(configStoreSocketUrl, (request, respond) => {
      respond({ success: false, data: config });
    });

    const rsPub = socket('pub');
    rsPub.bindSync(reportServicePubUrl);

    const rsRep = new SnapshotResponder(reportServiceRepUrl, (request, respond) => {
      respond({ success: true, data: undefined });
    });

    const as = new AnalyticsService();
    try {
      await as.start();
      expect(true).toBe(false);
    } catch (ex) {
      expect(ex.message).toBe('Analytics failed to get the config.');
    } finally {
      if (as) await as.stop();
      await delay(10);
      rsPub.unbindSync(reportServicePubUrl);
      configServer.dispose();
      rsPub.close();
      rsRep.dispose();
    }
  });
開發者ID:tangkaisky,項目名稱:r2,代碼行數:34,代碼來源:analytics.test.ts

示例2: test

  test('server: invalid message', async () => {
    let store: JsonConfigStore;
    let client: Socket;
    try {
      const validator = { validate: (config: ConfigRoot) => true };
      store = new JsonConfigStore(validator);
      store.TTL = 5;
      expect(store.config.minSize).toBe(0.01);

      client = socket('req');
      client.connect(configStoreSocketUrl);
      const reply = await new Promise(resolve => {
        client.once('message', resolve);
        client.send('invalid message');
      });
      const parsed = parseBuffer(reply);
      expect(parsed.success).toBe(false);
      expect(parsed.reason).toBe('invalid message');
      expect(store.config.minSize).toBe(0.01);
    } catch (ex) {
      console.log(ex);
      if (process.env.CI && ex.message === 'Address already in use') return;
      expect(true).toBe(false);
    } finally {
      store.close();
      client.close();
    }
  });
開發者ID:tangkaisky,項目名稱:r2,代碼行數:28,代碼來源:JsonConfigStore.test.ts


注:本文中的zeromq.socket函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。