Last active
March 15, 2017 22:23
-
-
Save barbagrigia/c9fc33da997b12bf416f6a1b01ebbc6d to your computer and use it in GitHub Desktop.
shouldReturnPromise - к слову я с некоторых пор весь код функции обычно держу в промисе, чтобы любые синхронные/асинхронные исключения были пойманы
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
function shouldReturnPromise (param) { | |
return Promise.resolve() | |
.then(() => { | |
if (param === undefined) { throw new Error() } // можно кинуть исключение, и промис реджекнется | |
if (param) { return Promise.resolve(true) } // можно вернуть промис | |
return false // можно вернуть значение | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment