purescript-hareactive icon indicating copy to clipboard operation
purescript-hareactive copied to clipboard

Running Aff and timing

Open paldepind opened this issue 6 years ago • 0 comments

@erisco asked on the PureScript Slack wether or not runStreamAff runs Affs in parallel or sequentially. This made me realize that there is no way to control that currently. @limemloh and I have discussed it and this is what I propose.

We will have two ways of running Affs from streams. One, runStreamAff which runs effects in parallel and an alternative runStreamAffPar which takes an integer n specifying that only n threads may run in parallel. Then runStreamAff is essentially the same as runStreamAffPar Infinity and runStreamAffPar 1 runs the Affs completely sequentially.

These are the types:

runStreamAff :: forall a. Stream (Aff a) -> Now (Stream (Future (Either Error a)))
runStreamAffPar :: forall a. Int -> Stream (Aff a) -> Now (Future (Either Error a))

Unlike the current runStreamAff these delivers their result as Futures. To flatten and order these we will add the following functions:

joinFutures :: forall a. Stream (Future a) -> Stream a
joinFuturesLatest :: forall a. Stream (Future a) -> Stream a
joinFuturesOrdered :: forall a. Stream (Future a) -> Stream a

The first simply delivers the result as they come back, the second discards old results (what you want for the zip code example) and the last one delivers results in the same order that they came in, delaying results if some preceding Affs are slow.

Does this handle all the different orderings that one may want? What do you think @erisco?

paldepind avatar Sep 03 '19 10:09 paldepind