Skip to content

Commit db4a9ea

Browse files
committed
Merge branch 'pr/1' into main
2 parents 0641142 + b6a2b73 commit db4a9ea

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

main.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ module.exports = (autoInit = true) => {
8989
/** List of subscribed symbols */
9090
let subscribed = [];
9191

92+
/** Websockets status calls */
93+
let isEnded = false;
94+
9295
/**
9396
* Send a custom packet
9497
* @param {string} t Packet type
@@ -184,9 +187,15 @@ module.exports = (autoInit = true) => {
184187

185188
/**
186189
* Close the websocket connection
187-
* @param {string} symbol Market symbol (Example: BTCEUR or COINBASE:BTCEUR)
190+
* @return {Promise<void>} When websocket is closed
188191
*/
189-
end() { ws.close(); },
192+
end() {
193+
return new Promise((cb) => {
194+
isEnded = true;
195+
ws.close();
196+
cb();
197+
});
198+
},
190199

191200
getUser,
192201
getChartToken,
@@ -290,6 +299,8 @@ module.exports = (autoInit = true) => {
290299
}
291300

292301
chartCBs[chartSession] = (packet) => {
302+
if (isEnded) return;
303+
293304
if (['timescale_update', 'du'].includes(packet.type)) {
294305
updatePeriods(packet);
295306
onUpdate([...periods].reverse());

0 commit comments

Comments
 (0)