*Remove timer

*Remove check for error on response?.data
*Refactor stream logic to not stream the done message
This commit is contained in:
Derrick Hammer 2022-08-21 21:44:56 -04:00
parent afdeca0bca
commit 524372c49b
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 5 additions and 11 deletions

View File

@ -195,17 +195,14 @@ async function rpcCall(
) {
const socket = await dht.connect(relay);
return new Promise((resolve, reject) => {
let timer: NodeJS.Timeout;
let dataCount = 0;
socket.on("data", (res) => {
if (timer && timer.close) {
clearTimeout(timer as number);
}
dataCount++;
const response = unpack(res);
if (!response || response.error || (response && response?.data?.error)) {
if (!response || response.error) {
socket.end();
reject(response?.error || response?.data?.error);
reject(response?.error);
return;
}
@ -216,11 +213,12 @@ async function rpcCall(
}
if (stream) {
stream(response?.data.data);
if (response?.data.done) {
socket.end();
resolve(true);
return;
}
stream(response?.data.data);
}
});
socket.write("rpc");
@ -232,10 +230,6 @@ async function rpcCall(
force: true,
})
);
/* timer = setTimeout(() => {
socket.end();
reject("timeout");
}, 10 * 1000) as NodeJS.Timeout;*/
});
}