-
-
Notifications
You must be signed in to change notification settings - Fork 513
Task
Giulio Canti edited this page Sep 2, 2022
·
4 revisions
Taskis 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
ApplyParandApplySeq?
ApplyPar runs tasks in parallel, ApplySeq runs tasks sequentially
What does
apSdo?
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' }