Published on

Introduction to Effect, Michael Arnaldi, WorkerConf 2022 Dornbirn

Authors

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

Fallback text 1

Promise.all but for each N items, awaiting to resolve the N first to not blow the API

Fallback text 2

Always having N API calls at the same time running (a lot complex)

Fallback text 3

Sometimes we want to have the option to interrupt the api calls

Fallback text 4

And the option to retry when an error occur

Fallback text 5

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!

Fallback text 6

It's good to create a file that exports what you need:

Fallback text 7
Fallback text 8

PS: never it's the list of requirements it needs to run the effect

Fallback text 9

PS: unsafeRunAsyncWith is a helper function that wraps errors we don't expect to happen

Fallback text 10
Fallback text 11
Fallback text 12
Fallback text 13
Fallback text 14
Fallback text 15
Fallback text 16
Fallback text 17
Fallback text 18

What Effect provide for us?

Fallback text 19
Fallback text 20