Skip to content
Giulio Canti edited this page Sep 2, 2022 · 4 revisions

FAQ

Task is a lazy promise that can't fail, any example of a promise that can't fail?

import * as T from 'fp-ts/Task'

const task: T.Task<void> = () =>
  new Promise((resolve) => setTimeout(resolve, 1000))

What's the difference between ApplyPar and ApplySeq?

ApplyPar runs tasks in parallel, ApplySeq runs tasks sequentially

What does apS do?

It allows you to create an Structured set of values in parallel since it utilizes the parallel Apply instance of Task

import * as T from 'fp-ts/Task'
import { pipe } from 'fp-ts/function'

pipe(
  T.Do,
  T.apS('foo', pipe(T.of('a'), T.delay(1000))),
  T.apS('bar', pipe(T.of('b'), T.delay(2000)))
)().then(console.log) // => { foo: 'a', bar: 'b' }
Clone this wiki locally