Effect CommunityEC
Effect Community3y ago
12 replies
matias

Running Conditional Branches in TypeScript

How can I run conditional branches?

I have this (wrong) code

export async function main(event: SQSEvent) {
    const records: SQSRecord[] = event.Records;
    Effect.forEachPar(
        records,
        flow(
            parseRecord,
            Effect.flatMap((msg) => {
                return Effect.ifEffect(
                    canJobBeProcessed(msg.jobId),
                    () => {
                        console.log('Can be processed')
                        return Effect.succeed(true)
                    },
                    () => {
                        console.log('Too many retry')
                        return Effect.fail(false)
                    }
                )
            })
        )
    )

}

The canJobBeProcessed(msg.jobId) returns Effect<never, boolean, boolean>

The result of that needs to be used to decide what workflow need to run after
Was this page helpful?