本文整理汇总了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();
}
});
示例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();
}
});