mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
25 lines
609 B
JavaScript
25 lines
609 B
JavaScript
const scheduledExecutions = {};
|
|
|
|
/**
|
|
* Subsequent calls will not move the timer to future. The first caller determines the time of execution.
|
|
*
|
|
* The good thing about synchronous better-sqlite3 is that this cannot interrupt transaction. The execution will be called
|
|
* only outside of a transaction.
|
|
*/
|
|
function scheduleExecution(name, milliseconds, cb) {
|
|
if (name in scheduledExecutions) {
|
|
return;
|
|
}
|
|
|
|
scheduledExecutions[name] = true;
|
|
|
|
setTimeout(() => {
|
|
delete scheduledExecutions[name];
|
|
|
|
cb();
|
|
}, milliseconds);
|
|
}
|
|
|
|
module.exports = {
|
|
scheduleExecution
|
|
}; |