Skip to content

Async functions that return TaskEither #1426

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

You must be logged in to vote

but now I can't use await statement anymore

you shouldn't need to use await in most cases, you can use map and chain instead:

import { pipe } from 'fp-ts/function'
import * as TE from 'fp-ts/TaskEither'

// -------------------------------------------------------------------------------------
// promise-based
// -------------------------------------------------------------------------------------

const promiseBasedAPI = async (s: string): Promise<number> => Promise.resolve(s.length)

const promiseBasedProgram = async (s: string): Promise<boolean> => {
  const n = await promiseBasedAPI(s)
  return n > 0
}

// -------------------------------------------------------------------------------…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nikkonrom
Comment options

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