Created
February 2, 2024 09:22
-
-
Save indiejoseph/53632e1a2b8ee3ab04fd7a53b6569aa5 to your computer and use it in GitHub Desktop.
Promise race timeout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const wait = ms => new Promise(resolve => setTimeout(resolve, ms)); | |
const timeout = (p, ms) => Promise.race([p, wait(ms).then(() => { | |
throw new Error("Timeout after " + ms + " ms"); | |
})]); | |
export const pubsubFunction: CloudEventFunction<{ | |
message: { data: string }; | |
}> = async () => { | |
timeout(checkShellTransactions(), 3 * 60 * 1000) // 3 minutes ms | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment