fix: s13n

This commit is contained in:
cha0s 2021-04-21 09:33:46 -05:00
parent 0042270f62
commit b62f71bb3c

View File

@ -27,7 +27,14 @@ export default (latus) => (Resource) => (
if (this._synchronized[type]?.[id]) { if (this._synchronized[type]?.[id]) {
const promises = []; const promises = [];
for (let i = 0; i < packet.data.packets.length; i++) { for (let i = 0; i < packet.data.packets.length; i++) {
promises.push(this._synchronized[type][id].acceptPacket(packet.data.packets[i])); const update = packet.data.packets[i];
promises.push(
Promise
.resolve(this._synchronized[type][id])
.then((resource) => {
resource.acceptPacket(update);
}),
);
} }
await Promise.all(promises); await Promise.all(promises);
} }
@ -52,10 +59,12 @@ export default (latus) => (Resource) => (
this._synchronized[type] = {}; this._synchronized[type] = {};
} }
if (this._synchronized[type][id]) { if (this._synchronized[type][id]) {
await this._synchronized[type][id].load(json); await (await this._synchronized[type][id]).load(json);
} }
else { else {
this._serializer.create(`${type}:${id}`, Resource.load(json)); const later = Resource.load(json);
this._synchronized[type][id] = later;
this._serializer.create(`${type}:${id}`, later);
await this._serializer.later(`${type}:${id}`, (resource) => { await this._serializer.later(`${type}:${id}`, (resource) => {
this._synchronized[type][id] = resource; this._synchronized[type][id] = resource;
}); });