Created
October 7, 2019 13:41
-
-
Save qguv/ba75174ec13e9e685dc271b77bc81647 to your computer and use it in GitHub Desktop.
higher_order.js: create wrapped versions of promise generator functions
This file contains hidden or 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
// 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