我有一些代码可以将数组中的值转换为异步调用:
const createDiscordChannels = flow(
A.map((channel: CreateChannelDto) => ({
...channel,
provider,
externalServerId: providerId,
})),
//* ? We need to check all the channels before we do anything
//* because otherwise we can end up in an inconsistent state
A.map(agentDispatcher.isChannelValid), // ? returns TaskEither
A.map(TE.flatMap(agentDispatcher.ensureChannelExists)), // ? creates race condition
A.map(RTE.fromTaskEither),
RTE.sequenceArray
);
我的问题是,A.map(TE.flatMap(agentDispatcher.ensureChannelExists))
将创建一堆并行执行的TaskEither
,从而产生竞争条件.
有没有一种方法可以创建并立即创建await个TaskEither
,以便按顺序而不是并行执行它们?