feat(outboundQueue): implement serial outbound job queue and enhance global state configuration

This commit is contained in:
Ivan
2026-04-12 17:03:40 -05:00
parent 5f161b7e17
commit f84afa5d77
2 changed files with 45 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ const globalState = reactive({
authSessionResolved: true,
authEnabled: false,
authenticated: false,
detailedOutboundSendStatus: false,
unreadConversationsCount: 0,
activeCallTab: "phone",
blockedDestinations: [],
@@ -21,4 +22,12 @@ const globalState = reactive({
},
});
export function mergeGlobalConfig(next) {
if (!next || typeof next !== "object") {
return;
}
const prev = globalState.config && typeof globalState.config === "object" ? globalState.config : {};
globalState.config = { ...prev, ...next };
}
export default globalState;

View File

@@ -0,0 +1,36 @@
/**
* Serial outbound job queue: one job runs at a time so later messages reuse
* the route established while sending earlier ones to the same peer.
*/
export function createOutboundQueue(processJob) {
const queue = [];
let running = false;
async function run() {
if (running) {
return;
}
running = true;
try {
while (queue.length) {
const job = queue.shift();
await processJob(job);
}
} finally {
running = false;
}
}
return {
enqueue(job) {
queue.push(job);
void run();
},
get length() {
return queue.length;
},
get isRunning() {
return running;
},
};
}