Make Client.fetchBatch more reliable

This commit is contained in:
Simon Ser 2021-06-10 12:43:09 +02:00
parent ba92b3f677
commit 5b0bb43a24

View file

@ -163,7 +163,6 @@ export default class Client extends EventTarget {
if (msg.tags["batch"]) {
msgBatch = this.batches.get(msg.tags["batch"]);
if (msgBatch) {
msgBatch.messages.push(msg);
msg.batch = msgBatch;
}
}
@ -259,7 +258,6 @@ export default class Client extends EventTarget {
params: msg.params.slice(2),
tags: msg.tags,
parent: msgBatch,
messages: [],
};
this.batches.set(name, batch);
} else {
@ -539,17 +537,30 @@ export default class Client extends EventTarget {
}
fetchBatch(msg, batchType) {
var batchName = null;
var messages = [];
return this.roundtrip(msg, (msg) => {
if (batchName) {
var batch = msg.batch;
while (batch) {
if (batch.name === batchName) {
messages.push(msg);
break;
}
batch = batch.parent;
}
}
switch (msg.command) {
case "BATCH":
var enter = msg.params[0].startsWith("+");
var name = msg.params[0].slice(1);
if (enter) {
if (enter && msg.params[1] === batchType) {
batchName = name;
break;
}
var batch = this.batches.get(name);
if (batch.type === batchType) {
return batch;
if (!enter && name === batchName) {
return { ...this.batches.get(name), messages };
}
break;
case "FAIL":