本文整理汇总了TypeScript中events.EventEmitter.createRawProducer方法的典型用法代码示例。如果您正苦于以下问题:TypeScript EventEmitter.createRawProducer方法的具体用法?TypeScript EventEmitter.createRawProducer怎么用?TypeScript EventEmitter.createRawProducer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类events.EventEmitter
的用法示例。
在下文中一共展示了EventEmitter.createRawProducer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
channelManager.findOrCreateProducer = function (topic, options, unusedChannelTimeoutMs) {
let channel = producersByTopic[topic];
if (channel) return channel;
options = options ? options : {};
channel = producersByTopic[topic] = channelManager.createRawProducer(topic, options);
let unusedChannelTimeout;
channelManager.emit(channelManager.PRODUCER_NEW_TOPIC_EVENT, topic);
channel.publish_ = channel.publish;
channel.publish = function (message, cb) {
clearTimeout(unusedChannelTimeout);
if (unusedChannelTimeoutMs) {
unusedChannelTimeout = setTimeout(onUnusedChannelTimeout, unusedChannelTimeoutMs);
}
channel.publish_(message, function (err) {
if (err) return cb(err);
channelManager.emit(channelManager.PRODUCER_NEW_MESSAGE_EVENT, topic);
cb();
});
};
function onUnusedChannelTimeout() {
removeProducer(channel, topic);
}
return channel;
};