Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running Aff and timing #3

Open
paldepind opened this issue Sep 3, 2019 · 0 comments
Open

Running Aff and timing #3

paldepind opened this issue Sep 3, 2019 · 0 comments

Comments

@paldepind
Copy link
Member

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant