fvilante / NextRobot

The next robot framework
0 stars 0 forks source link

Compatibilize 'absolve' combinators #35

Open fvilante opened 4 years ago

fvilante commented 4 years ago

Absolve is(or should be) the inverse of pullout.

Types from Future and ZIO differs.

const absolve: <E, A>(fr: Future<void, Result<E, A>>) => Future<E, A>

const absolve: <R, E, A>(z: ZIO<R, E, Future<E, A>>) => ZIO<R, E, A>

Question is: 1) What is better? 2) What is the trade-off ?

note: Should Result also need the same concept ? Probably all monads which has 2 type parameters.

19

fvilante commented 4 years ago

Which is better? Result is Better

In bellow code:

const absolve: <E, A>(fr: Future<void, ???<E, A>>) => Future<E, A>

??? should be Result (or Either) instead of Future. The reason is Result is syncronous, while Future is asynchronous. As absolve is used many times along normal programming conditions, many Promises should be required to be chained if we use Future, slowing the computation.

ACTION If I use Result instead of Future could I avoid all this Promises chaining ?

20

fvilante commented 4 years ago

@fvilante you should also consider if run-time does start multiple paralel threads to run promises. If so, for complex computations it should be faster run Promises than run synchronous computations. For simple computations, synchronous calls should still work better.

ACTION Verify how existent Javascript's Run-time (ex: node.js, deno.ts, chrome, firefox) deals with schedulling Promises.

Does the javascript language has by design the requirement for single-threaded event loop run-time, or this is just a particular design decision of NodeJs.