fix: use command queue for batch event write
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Kieran 2024-01-19 13:25:14 +00:00
parent 72b98a4ab5
commit da6fa415dd
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
1 changed files with 8 additions and 3 deletions

View File

@ -31,9 +31,14 @@ let eventWriteQueue: Array<NostrEvent> = [];
async function insertBatch() {
// Only insert event batches when the command queue is empty
// This is to make req's execute first and not block them
if (relay && eventWriteQueue.length > 0 && cmdQueue.length === 0) {
relay.eventBatch(eventWriteQueue);
eventWriteQueue = [];
if (eventWriteQueue.length > 0 && cmdQueue.length === 0) {
await barrierQueue(cmdQueue, async () => {
if (relay) {
const toWrite = [...eventWriteQueue];
eventWriteQueue = [];
relay.eventBatch(toWrite);
}
});
}
setTimeout(() => insertBatch(), 100);
}