1

I was reading about Fluture, and one way to consume a Future is to call fork. That is all understandable so far but in documentation it states:
"Generally, one only needs to call fork in a single place in the entire program".

What does it mean? What if I'm using Futures to fetch some content from Api request, I would probably want to do this multiple times throughout the code each with different resolve functions. All of these Futures would then require their own forks, right?

Ansgar P.
  • 48
  • 5
  • 1
    `Fluture` is all about combining and passing around definitions or describtions of async computations. Providing a function to `fork` is the only means to actually perform the effect. This way everything before the invocation of `fork` is pure. The hard aspect of this approach is to don't break this huge composition along the way. With typed FP langs the compiler guides you but with JS it is solely your responsibility. –  Sep 25 '21 at 16:20

1 Answers1

2

It is expected that you build your entire program as a big Future, composed of smaller futures (like many Api calls chained to each other), and only in your main entrypoint do call fork().

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • Oh, I think I understand, I was so focused on that fetch example that I didn't consider that every other function can be a future as well. I guess it could even be used in event like user clicking on a button to trigger something. – Ansgar P. Sep 26 '21 at 00:42