Skip to content

Commit

Permalink
Fixed how listenkey error is handled
Browse files Browse the repository at this point in the history
  • Loading branch information
toant13 committed Sep 10, 2019
1 parent eb5c3d4 commit 4c2c464
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 31 deletions.
26 changes: 10 additions & 16 deletions dist/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,16 @@ var userEventHandler = function userEventHandler(cb) {
};

exports.userEventHandler = userEventHandler;
var keepStreamAlive = exports.keepStreamAlive = function keepStreamAlive(method, listenKey, correlationId) {
var keepStreamAlive = exports.keepStreamAlive = function keepStreamAlive(method, listenKey, correlationId, intervalId) {
return function () {
try {
console.log('[correlationId=' + correlationId + ' Binance, keeping alive listenKey=' + listenKey);
method({ listenKey: listenKey });
} catch (err) {

console.log('keepStreamAlive error:', err);
}
console.log('[correlationId=' + correlationId + ' Binance, keeping alive listenKey=' + listenKey);
method({ listenKey: listenKey }).catch(function (err) {
console.log('[correlationId=' + correlationId + ' listenKey issue: ' + err);
if (intervalId !== -1) {
clearInterval(intervalId);
console.log('[correlationId=' + correlationId + ' cleared listenKey interval');
}
});
};
};

Expand Down Expand Up @@ -372,14 +373,7 @@ var user = function user(opts) {
};

int = setInterval(function () {
try {
keepStreamAlive(keepDataStream, listenKey, correlationId)();
} catch (err) {
console.log('[correlationId=' + correlationId + ' listenKey issue: ' + err);
if (int !== -1) {
clearInterval(int);
}
}
keepStreamAlive(keepDataStream, listenKey, correlationId, int)();
}, 50e3);
keepStreamAlive(keepDataStream, listenKey, correlationId)();

Expand Down
24 changes: 9 additions & 15 deletions src/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,15 @@ export const userEventHandler = cb => msg => {
cb(userTransforms[type] ? userTransforms[type](rest) : { type, ...rest })
}

export const keepStreamAlive = (method, listenKey, correlationId) => () => {
try {
export const keepStreamAlive = (method, listenKey, correlationId, intervalId) => () => {
console.log(`[correlationId=${correlationId} Binance, keeping alive listenKey=${listenKey}`)
method({ listenKey })
} catch (err) {

console.log('keepStreamAlive error:', err)
}
method({ listenKey }).catch((err)=>{
console.log(`[correlationId=${correlationId} listenKey issue: ${err}`)
if(intervalId !== -1) {
clearInterval(intervalId)
console.log(`[correlationId=${correlationId} cleared listenKey interval`)
}
})
}

let int = -1
Expand All @@ -283,14 +284,7 @@ const user = opts => (cb, correlationId) => {
}

int = setInterval(() => {
try {
keepStreamAlive(keepDataStream, listenKey, correlationId)()
} catch (err) {
console.log(`[correlationId=${correlationId} listenKey issue: ${err}`)
if(int !== -1){
clearInterval(int)
}
}
keepStreamAlive(keepDataStream, listenKey, correlationId, int)()
}, 50e3)
keepStreamAlive(keepDataStream, listenKey, correlationId)()

Expand Down

0 comments on commit 4c2c464

Please sign in to comment.