mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
18 lines
782 B
JavaScript
18 lines
782 B
JavaScript
'use strict';
|
|
const { AsyncLocalStorage } = require('node:async_hooks');
|
|
const { canonical } = require('../../models/lib/changeHistoryIntegrity');
|
|
const storage = new AsyncLocalStorage();
|
|
async function withSyncActivityDeferred(activity, work) {
|
|
const scope = { expected: canonical(activity), slots: new Set(['timestamps', 'rules', 'notifications']), active: true };
|
|
return storage.run(scope, async () => {
|
|
try { return await work(); } finally { scope.active = false; }
|
|
});
|
|
}
|
|
function deferSyncActivity(kind, activity) {
|
|
const scope = storage.getStore();
|
|
if (!scope?.active || !scope.slots.has(kind) || canonical(activity) !== scope.expected) return false;
|
|
scope.slots.delete(kind);
|
|
return true;
|
|
}
|
|
module.exports = { withSyncActivityDeferred, deferSyncActivity };
|