本文整理匯總了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();
}
});