await-on
Go-like error handling for async JavaScript functions.
Installation
This package is distributed via npm:
npm install @antoniovdlc/await-on
Motivation
Async functions in JavaScript are great! They allow you to write asynchronous code as if it were synchronous.
The main drawback I personally experience is having to write code like this:
try {
const result = await someFunc()
// Do something with `result`
} catch (err) {
// Handle error
}
Having had some past experience using Go, and after some time to fully understand the elegance of its simplistic error handling approach, it felt right to try to replicate it:
result, err := someFunc()
if err != nil {
// Handle error
}
// Do something with `result`
This is why this package exists, so that we can write asynchronous JavaScript code in a style as close as possible to that of Go:
const
…