这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,29 @@ var LGTV = function (config) {

switch (type) {
case 'request':
// set callback timeout
var timeoutId =
setTimeout(function () {
// remove callback first, in case the response
// comes back while we're processing the error.
delete callbacks[cid];

// notify of the error.
cb(new Error('timeout'));
}, config.timeout);

callbacks[cid] = function (err, res) {
// clear the timeout first, so the callback processing
// time doesn't count against the timeout.
clearTimeout(timeoutId);

// call the callback
cb(err, res);

// remove callback after first call
delete callbacks[cid];
};

// set callback timeout
setTimeout(function () {
cb(new Error('timeout'));
// remove callback
delete callbacks[cid];
}, config.timeout);
break;

case 'subscribe':
Expand Down