Skip to content

Commit

Permalink
feat: Update race conition to break on return
Browse files Browse the repository at this point in the history
  • Loading branch information
kevintyj committed Jun 28, 2024
1 parent f2ec49b commit 2f5fa22
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
9 changes: 6 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40928,12 +40928,15 @@ async function run() {
*/
void (async () => {
const timeoutInput = core.getInput('timeout') ?? '25';
const timeout = Number.parseInt(timeoutInput, 10) * 1000;
const timeoutSeconds = Number.parseInt(timeoutInput, 10) * 1000;
let timeoutId = setTimeout(() => { }, 0); // Default to timeout
const timeoutPromise = new Promise((_, reject) => {
setTimeout(() => reject(new Error('Action timed out')), timeout);
timeoutId = setTimeout(() => reject(new Error('Action timed out')), timeoutSeconds);
});
try {
return await Promise.race([run(), timeoutPromise]);
const result = await Promise.race([run(), timeoutPromise]);
clearTimeout(timeoutId);
return result;
}
catch (err) {
errHandle(err);
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ async function run(): Promise<boolean> {
*/
void (async () => {
const timeoutInput: string = core.getInput('timeout') ?? '25';
const timeoutSeconds = Number.parseInt(timeoutInput, 10) * 1000;

const timeout = Number.parseInt(timeoutInput, 10) * 1000;

let timeoutId: NodeJS.Timeout = setTimeout(() => {}, 0); // Default to timeout
const timeoutPromise = new Promise((_, reject) => {
setTimeout(() => reject(new Error('Action timed out')), timeout);
timeoutId = setTimeout(() => reject(new Error('Action timed out')), timeoutSeconds);
});

try {
return await Promise.race([run(), timeoutPromise]);
const result = await Promise.race([run(), timeoutPromise]);
clearTimeout(timeoutId);
return result;
}
catch (err) {
handleError(err);
Expand Down

0 comments on commit 2f5fa22

Please sign in to comment.