Skip to content

Instantly share code, notes, and snippets.

@qguv
Created October 7, 2019 13:41
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 qguv/ba75174ec13e9e685dc271b77bc81647 to your computer and use it in GitHub Desktop.
Save qguv/ba75174ec13e9e685dc271b77bc81647 to your computer and use it in GitHub Desktop.
higher_order.js: create wrapped versions of promise generator functions
// produce a wrapped promise generator whose promises regenerate instead of rejecting
export function retrying(func, n=Infinity) {
return n == 1
? func
: () => func().catch(retrying(func, n - 1));
}
// produce a wrapped promise generator whose promises ignore rejections
export function noreject(func) {
return () => func().catch(() => {});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment