Skip to content

Request for guidance: CancellableTaskEither #1440

Answered by gcanti
andrewreineke asked this question in Q&A
Discussion options

You must be logged in to vote

@andrewreineke you can check isCancelled before calling saveUser

const REQUEST_CANCELLED = 'REQUEST_CANCELLED' as const

export const handleRequestWithCancellation: HandleRequestWithCancellation = ({ userId, isCancelled }) =>
  pipe(
    getUser(userId),
    TE.chainW((user) =>
      pipe(
        TE.rightIO(isCancelled),
        TE.chainW((b) => (b ? TE.left(REQUEST_CANCELLED) : saveUser(user)))
      )
    )
  )

or using "do notation"

export const handleRequestWithCancellation2: HandleRequestWithCancellation = ({ userId, isCancelled }) =>
  pipe(
    TE.Do,
    TE.bind('user', () => getUser(userId)),
    TE.bind('isCancelled', () => TE.rightIO(isCancelled)),
    TE.chainW(({ isCancelled,

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@andrewreineke
Comment options

@gcanti
Comment options

Answer selected by andrewreineke
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants