INNER CODE UNIT · TypeScript
Promise
VincentJouanne/nest-clean-architecture · common/utils/executeTask.ts:13
return new Promise((resolve, reject) => {
pipe(result, Either.fold(reject, resolve));
});
};
/**
* Given a taskEither, execute the task, and call the onLeft or OnRight callback.
*
* @param task: a TaskEither
* @param onLeft
* @param onRight
*/
export const executeAndHandle = async <E, A, B>(task: TaskEither<E, A>, onLeft: (error: E) => B, onRight: (data: A) => B): Promise<B> => {
const result = await task();
return pipe(result, Either.fold<E, A, B>(onLeft, onRight));
};