Skip to content

Commit

Permalink
fix duplicate proc
Browse files Browse the repository at this point in the history
  • Loading branch information
117 committed Jan 16, 2025
1 parent 73df4cd commit e9675ff
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@117/interrupt",
"description": "Task queue for interrupt handling.",
"version": "2.0.3",
"version": "2.0.4",
"exports": "./mod.ts",
"imports": {
"@/": "./",
Expand Down
14 changes: 12 additions & 2 deletions src/onInterrupt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/** @module interrupt */

/** Represents whether the task queue is being processed. */
let isExecuting = false;

/**
* Represents a task to be executed with an optional error handler.
* @interface
Expand Down Expand Up @@ -69,8 +72,15 @@ const processTasks = async (): Promise<void> => {
* @async
* @returns {Promise<void>}
*/
const onBeforeInterrupt = async (): Promise<void> =>
await processTasks().then(() => Deno.exit());
const onBeforeInterrupt = async (): Promise<void> => {
if (isExecuting) {
return;
}

isExecuting = true;
await processTasks();
Deno.exit();
};

/** Registers the interrupt handlers for SIGINT and SIGTERM signals. */
Deno.addSignalListener("SIGINT", onBeforeInterrupt);
Expand Down

0 comments on commit e9675ff

Please sign in to comment.