function goLike<F extends (...args: any) => any, E = unknown>(func: F, ctx: unknown = undefined) {
return (...args: Parameters<F>): [ReturnType<F> | null, E | null] => {
try {
const res = func.apply(ctx, args)
return [res, null]
} catch (e) {
return [null, e as E]
}
}
}
Identifying the Problems
Callbacks
Everyone is aware of the popular "callback hells", but we mostly see those with respect to success responses, what if you need to handle the errors as well.