0.9.4 • Published 6 years ago

error-first v0.9.4

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

error-first

Convert async/await try/catch to [error, result]

tl;dr

import errorFirst from 'error-first'

const [error, result] = await errorFirst(doSomething)

Details

Given an async operation

const addAsync = async (a, b) => {
    if (a == null || b == null) {
        throw 'Argument Error'
    }

    return a + b
}

With error-first

import errorFirst from 'error-first'
// const errorFirst = require('error-first').default

const [error, result] = await errorFirst(addAsync(1, 2)) // [undefined, 3]

With standard async/await

let result = null

try {
    result = await addAsync(1, 2)
} catch(error) {
    // Do something with error
}
0.9.4

6 years ago

0.9.3

6 years ago

0.9.2

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago