Created
July 3, 2020 03:23
-
-
Save jodyheavener/365c70a7cc2da7465a394e3ba60fd30a to your computer and use it in GitHub Desktop.
short-circuit attempts thwarted by async
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
| // version 1 - every | |
| if (!await conditionChecks.every(async (check) => { | |
| const result = await check(); | |
| if (!result.passing) { | |
| return false; | |
| } | |
| if (result.key && result.value !== undefined) { | |
| satisfiedConditions[result.key] = surveyGizmoSafe(result.value); | |
| } | |
| return true; | |
| })) { | |
| return failureRes; | |
| } | |
| // version 2 - reduce | |
| const satisfiedConditions = await conditionChecks.reduce( | |
| async (output, check) => { | |
| if (!output) { | |
| return false; | |
| } | |
| const result = await check(); | |
| if (!result.passing) { | |
| return false; | |
| } | |
| if (result.key && result.value !== undefined) { | |
| output[result.key] = surveyGizmoSafe(result.value); | |
| } | |
| return output; | |
| }, | |
| {} | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment