Skip to content

Instantly share code, notes, and snippets.

@indiejoseph
Created February 2, 2024 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indiejoseph/53632e1a2b8ee3ab04fd7a53b6569aa5 to your computer and use it in GitHub Desktop.
Save indiejoseph/53632e1a2b8ee3ab04fd7a53b6569aa5 to your computer and use it in GitHub Desktop.
Promise race timeout
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