forked from CringeStudios/gamja
Make Client.fetchBatch more reliable
This commit is contained in:
parent
ba92b3f677
commit
5b0bb43a24
@ -163,7 +163,6 @@ export default class Client extends EventTarget {
|
|||||||
if (msg.tags["batch"]) {
|
if (msg.tags["batch"]) {
|
||||||
msgBatch = this.batches.get(msg.tags["batch"]);
|
msgBatch = this.batches.get(msg.tags["batch"]);
|
||||||
if (msgBatch) {
|
if (msgBatch) {
|
||||||
msgBatch.messages.push(msg);
|
|
||||||
msg.batch = msgBatch;
|
msg.batch = msgBatch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -259,7 +258,6 @@ export default class Client extends EventTarget {
|
|||||||
params: msg.params.slice(2),
|
params: msg.params.slice(2),
|
||||||
tags: msg.tags,
|
tags: msg.tags,
|
||||||
parent: msgBatch,
|
parent: msgBatch,
|
||||||
messages: [],
|
|
||||||
};
|
};
|
||||||
this.batches.set(name, batch);
|
this.batches.set(name, batch);
|
||||||
} else {
|
} else {
|
||||||
@ -539,17 +537,30 @@ export default class Client extends EventTarget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fetchBatch(msg, batchType) {
|
fetchBatch(msg, batchType) {
|
||||||
|
var batchName = null;
|
||||||
|
var messages = [];
|
||||||
return this.roundtrip(msg, (msg) => {
|
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) {
|
switch (msg.command) {
|
||||||
case "BATCH":
|
case "BATCH":
|
||||||
var enter = msg.params[0].startsWith("+");
|
var enter = msg.params[0].startsWith("+");
|
||||||
var name = msg.params[0].slice(1);
|
var name = msg.params[0].slice(1);
|
||||||
if (enter) {
|
if (enter && msg.params[1] === batchType) {
|
||||||
|
batchName = name;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
var batch = this.batches.get(name);
|
if (!enter && name === batchName) {
|
||||||
if (batch.type === batchType) {
|
return { ...this.batches.get(name), messages };
|
||||||
return batch;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "FAIL":
|
case "FAIL":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user