Skip to content

Instantly share code, notes, and snippets.

@barbagrigia
Last active March 15, 2017 22:23
Show Gist options
  • Save barbagrigia/c9fc33da997b12bf416f6a1b01ebbc6d to your computer and use it in GitHub Desktop.
Save barbagrigia/c9fc33da997b12bf416f6a1b01ebbc6d to your computer and use it in GitHub Desktop.
shouldReturnPromise - к слову я с некоторых пор весь код функции обычно держу в промисе, чтобы любые синхронные/асинхронные исключения были пойманы
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