mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-14 04:52:28 +08: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
|
||
|
};
|