我在一个node.js项目中使用pubnub。我可以初始化pubnub并发布如下消息:
Node.js
var PUBNUB = require('pubnub');
var pubnub = PUBNUB.init({
publish_key : 'demo',
subscribe_key : 'demo'
});
var CHANNEL = 'test1234';
pubnub.subscribe({
channel: CHANNEL,
message: function (message) {
console.log('Received message:', message);
// unsubscribe again
pubnub.unsubscribe({channel: CHANNEL});
// PROBLEM: The node.js process does not exit because pubnub is still
// active. How to close the pubnub connection so it's completely
// gone from memory?
},
connect: function () {
// send a test message
pubnub.publish({channel: CHANNEL, message: 'hello world!'});
}
});但是如何关闭pubnub实例呢?这样它就从内存和事件循环中消失了,并且不能让node.js进程继续运行。
我在API文档中找不到任何东西,于是尝试了pubnub.close()、pubnub.destroy()和pubnub.disconnect(),但没有成功。
发布于 2015-02-06 08:22:41
这个问题在更新版本pubnub (当前版本为3.7.8)中得到了解决。
https://stackoverflow.com/questions/25806223
复制相似问题