Skip to content

Add forkAll combinator #45

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

Merged
merged 2 commits into from
Feb 22, 2016
Merged

Conversation

natefaubion
Copy link
Collaborator

No description provided.

forkAll :: forall f e a. (Foldable f) => f (Aff e a) -> Aff e Unit
```

Forks many asynchronous computation at once, ignoring the results.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add a guarantee that all computations will be forked synchronously.

@natefaubion
Copy link
Collaborator Author

I went ahead and made it mirror forkAff, so that it returns a canceler that can be used to cancel all of the forked computations. I also went ahead and made the canceler stack safe, since it was very easy to trigger a stack overflow using the Monoid instance (I could only run the test I made with a small number since the timeout canceler is synchronous).

@jdegoes
Copy link
Contributor

jdegoes commented Feb 16, 2016

@natefaubion 👍 Looks great, @garyb you want to do a final review?

@garyb
Copy link
Member

garyb commented Feb 16, 2016

Will do, once 2.5 is out!

acc.push(aff(voidF, voidF));
return acc;
}
})([])(affs);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah. I don't love it either :/

I might be able to extract out a helper to share with cancelWith.

On Feb 22, 2016, at 4:11 AM, Gary Burgess [email protected] wrote:

In src/Control/Monad/Aff.js:

@@ -96,6 +96,61 @@ exports._forkAff = function (nonCanceler, aff) {
};
}

+exports._forkAll = function (nonCanceler, foldl, affs) {

  • var voidF = function(){};
  • return function(success, error) {
  • var cancelers = foldl(function(acc) {
  •  return function(aff) {
    
  •    acc.push(aff(voidF, voidF));
    
  •    return acc;
    
  •  }
    
  • })([])(affs);


Reply to this email directly or view it on GitHub.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, I can see it's fine, it's just the mutating of the array in the fold while constructing it that made me look twice. 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. Thought you were referring to the sheer length of this function. Hard to tell in email sometimes

@garyb
Copy link
Member

garyb commented Feb 22, 2016

Looks good to me too! 👍

garyb added a commit that referenced this pull request Feb 22, 2016
@garyb garyb merged commit e3f6277 into purescript-contrib:master Feb 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants