Persist & replicate in parallel
parent
2b6cc135d3
commit
b4e0ebd600
26
antietcd.js
26
antietcd.js
|
@ -86,13 +86,29 @@ class AntiEtcd
|
|||
|
||||
async persistAndReplicate(msg)
|
||||
{
|
||||
if (this.persistence)
|
||||
{
|
||||
await this.persistence.persistChange(msg);
|
||||
}
|
||||
let res = [];
|
||||
if (this.cluster)
|
||||
{
|
||||
await this.cluster.replicateChange(msg);
|
||||
// We have to guarantee that replication is processed sequentially
|
||||
// So we have to send messages without first awaiting for anything!
|
||||
res.push(this.cluster.replicateChange(msg));
|
||||
}
|
||||
if (this.persistence)
|
||||
{
|
||||
res.push(this.persistence.persistChange(msg));
|
||||
}
|
||||
if (res.length)
|
||||
{
|
||||
res = await Promise.allSettled(res);
|
||||
const errors = res.filter(r => r.status == 'rejected');
|
||||
if (errors.length)
|
||||
{
|
||||
for (const e of errors)
|
||||
{
|
||||
console.error(e.reason);
|
||||
}
|
||||
throw errors[0].reason;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue