Skip to content

Commit

Permalink
Fixed promise timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
pastelsky committed Jan 3, 2024
1 parent f3d9f10 commit 062f421
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions server/workers/docs-builder-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ setInterval(() => {
}
}, 5000);

function promiseTimeout(promise, timeout) {
const timeoutPromise = new Promise((resolve, reject) => {
setTimeout(() => {
reject(
new Error(
`PROMISE_TIMEOUT: Promise timed out after ${timeout} seconds`,
),
);
}, timeout);
function promiseTimeout(promise, ms = 10000) {
let timeout = new Promise((resolve, reject) => {
let id = setTimeout(() => {
clearTimeout(id);
reject("Promise timed out in " + ms + "ms.");
}, ms);
});

return Promise.race([timeoutPromise, timeout]);
return Promise.race([promise, timeout]).then(
(result) => result,
(error) => Promise.reject(error),
);
}

module.exports = async (job) => {
Expand All @@ -44,7 +44,7 @@ module.exports = async (job) => {
generateDocsForPackage(job.data.packageJSON, {
force: job.data.force,
}),
120,
120 * 1000,
);
console.log("Finished job", job);

Expand Down

0 comments on commit 062f421

Please sign in to comment.