Skip to content

Commit

Permalink
Use node:timers/promises for timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
d3xter666 committed Nov 14, 2023
1 parent 461c1da commit 8dadf92
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/processors/minifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import workerpool from "workerpool";
import Resource from "@ui5/fs/Resource";
import {getLogger} from "@ui5/logger";
const log = getLogger("builder:processors:minifier");
import {setTimeout as setTimeoutPromise} from "node:timers/promises";

const debugFileRegex = /((?:\.view|\.fragment|\.controller|\.designtime|\.support)?\.js)$/;

Expand All @@ -29,7 +30,7 @@ function getPool(taskUtil) {
maxWorkers
});
taskUtil.registerCleanupTask((force) => {
const attemptPoolTermination = () => {
const attemptPoolTermination = async () => {
log.verbose(`Attempt to terminate the workerpool...`);

if (!pool) {
Expand All @@ -40,9 +41,8 @@ function getPool(taskUtil) {
// convenient. When all the (available) workers are idle, then it's safe to terminate.
const {idleWorkers, totalWorkers} = pool.stats();
if (idleWorkers !== totalWorkers && !force) {
return new Promise((resolve) =>
setTimeout(() => resolve(attemptPoolTermination()), 100) // Retry after a while
);
await setTimeoutPromise(100); // Wait a bit workers to finish and try again
return attemptPoolTermination();
}

const poolToBeTerminated = pool;
Expand Down

0 comments on commit 8dadf92

Please sign in to comment.