Skip to content

Instantly share code, notes, and snippets.

@lorensr
Last active March 23, 2022 00:37
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 lorensr/836c6f730ed7df66dd85d07966fe4d14 to your computer and use it in GitHub Desktop.
Save lorensr/836c6f730ed7df66dd85d07966fe4d14 to your computer and use it in GitHub Desktop.
const { poll } = proxyActivities<typeof activities>({
startToCloseTimeout: '10m',
retryPolicy: {
initialInterval: '1h',
backoffCoefficient: 1
}
});
export const stopPolling = defineSignal('stopPolling');
export async function resumeAfterCancellation(url: string): Promise<any> {
let result: any;
try {
result = await CancellationScope.cancellable(async () => {
setHandler(stopPolling, () => void CancellationScope.current().cancel());
return await poll(url);
});
} catch (err) {
if (!isCancellation(err)) { throw err }
}
}
@bergundy
Copy link

You can make this shorter:

export async function resumeAfterCancellation(url: string): Promise<any> {
  try {
    await CancellationScope.cancellable(async () => {
      setHandler(stopPolling, () => void CancellationScope.current().cancel());
      return await poll(url);
    });
  } catch (err) {
    if (!isCancellation(err)) { throw err }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment