- Published on
Introduction to Effect, Michael Arnaldi, WorkerConf 2022 Dornbirn
- Authors
- Name
- Lucas Floriani
- @lucasfloriani13
Introduction to Effect, Michael Arnaldi, WorkerConf 2022 Dornbirn
Introduction to Effect, Michael Arnaldi, WorkerConf 2022 Dornbirn
Concurrency
We can have multiple ways to handle concurrency:
Simple Promise.all
Promise.all but for each N items, awaiting to resolve the N first to not blow the API
Always having N API calls at the same time running (a lot complex)
Sometimes we want to have the option to interrupt the api calls
And the option to retry when an error occur
And the list goes one...
- Logging
- Metrics
- Tracing
- Dependency Injection
- Etc
PS: Most of the code shown is hard to understand and hard to maintain
Effect
The code before is hard to compose together, this is one point of why effect ts was created.
Effect is a lazy promise, describes your intention, and you execute the start after the configuration (effect to a fiber). This makes possible composability and higher order behaviour.
Let's redo those codes with effect!
It's good to create a file that exports what you need:
PS: never it's the list of requirements it needs to run the effect
PS: unsafeRunAsyncWith is a helper function that wraps errors we don't expect to happen