Error-first callbacks were cool. Using mutable variables to hoist state when doing try/catch was not cool.
_.try function let’s you wrap a function to convert it to an error-first async function.
import * as _ from 'radash' const [err, user] = await _.try(api.users.find)(userId)
try is a reserved word this function is aliased as
try and actually named
tryit in the source.
You can curry
try if you like.
import * as _ from 'radash' const findUser = _.try(api.users.find) const [err, user] = await findUser(userId)
_.try function is 100% covered by tests. See them and contribute at GitHub.
See the source for
_.try on GitHub.