I'm facing a challenge with my code that involves the usage of ReaderTaskEither
:
export const AddUserToTeam = ({ userId, teamId }: AddUserToTeamDto) => {
return pipe(
// 👇 Uses ReaderTaskEither
Do,
bind("deps", () => ask<Deps>()),
bind("tx", ({ deps }) => fromTask(deps.createTransaction())),
bind("addToTeams", ({ deps, tx }) => {
return fromTaskEither(
// ...
);
}),
bindW("result", ({ deps, tx }) => {
return fromTaskEither(
deps.dispatcher.create(
// ...
)({ tx })
);
}),
);
};
My specific issue arises when I try to handle errors by calling rollback
on the interactive transaction (tx
) inside a fold
or mapLeft
, but I can't access the context containing tx
in either. How can I maintain a reference to tx
for handling errors?
It's important to note that I can't include tx
in Deps
since transactions are not used universally (they are optional).