mirror of
https://git.quad4.io/RNS-Things/MeshChatX.git
synced 2026-04-26 02:22:15 +00:00
feat(outboundQueue): implement serial outbound job queue and enhance global state configuration
This commit is contained in:
@@ -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;
|
||||
|
||||
36
meshchatx/src/frontend/js/outboundSendQueue.js
Normal file
36
meshchatx/src/frontend/js/outboundSendQueue.js
Normal 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;
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user