-
Notifications
You must be signed in to change notification settings - Fork 65
4.0.0 rewrite #106
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
4.0.0 rewrite #106
Conversation
I've added a bunch of tests and worked out a lot of the kinks. I still have more tests to add back pertaining to I'd like to detail the behavior around the threading model and exceptions, and the interplay of effect labels. I've removed the I've also tried something different here with regards to type AffModality eff =
( exception ∷ EXCEPTION
, async ∷ ASYNC
| eff
)
-- Needs to have alias inlined because synonym desugaring bug in instance declarations
instance monadEffAff ∷ EffectRowEquals eff1 (exception ∷ EXCEPTION, async ∷ ASYNC | eff2) ⇒ MonadEff eff1 (Aff eff2)
makeAff ∷ ∀ eff a. ((Either Error a → Eff (AffModality eff) Unit) → Eff (AffModality eff) (Canceler eff)) → Aff eff a In other words, any underlying someAff = makeAff \k -> do
thread <- launchAff do
delay (Milliseconds 100.0)
liftEff $ k (Right unit)
pure $ Canceler (flip killThread thread) Or in other words, take the continuation from one scheduler, launch a new one, and invoke the continuation from the new scheduler. The effect rows won't unify in this case. Even though this is how some things are implemented internally, I'd argue this is an inherently unsafe thing to do, so I've provided |
@paf31 suggested trying launchAff
:: forall eff1 eff2.
. Aff eff1
=> Eff (async :: ASYNC (exception :: EXCEPTION | eff1) | eff2) Unit I think this is interesting, and perhaps more accurately describes what's going on. |
@natefaubion Last time I tried that, the type inferencer had major problems, and adding labels of any kind selectively results in user-pain. What is the pain that adding |
Likely before fundeps? The EffectRowEquals constraints uses functional dependencies, so it should be the same as wrapping every Eff with But you are right, it just may not be worth it, and there are tons of instances in the current ecosystem where |
I think I will still elide the additional |
We have |
@syaiful6 We could probably formulate |
This still needs documentation updated, but otherwise the code is ready for review. |
The |
I wanted to make sure everything worked whether or not we decided to schedule forks (rather than evaluating immediately), and there were some edge cases that failed. That was a red flag to me, so I've refactored the internal Fiber API to be more robust, and at least manually verified that it works and all tests pass regardless of evaluation strategy around forks in case we decide to change it at some point. |
@jdegoes I think we just need to decide whether we want supervised threads to be the default, and what we should do about laws in purescript-contrib/purescript-fork#4 (comment). |
@natefaubion All right. Give me a day to think this over and we can hash out the details tomorrow. |
I've added |
I've changed the default behavior of |
This is ready to go. Would anyone like to review the README changes? |
README.md
Outdated
|
||
The library contains instances for `Semigroup`, `Monoid`, `Apply`, `Applicative`, `Bind`, `Monad`, `Alt`, `Plus`, `MonadPlus`, `MonadEff`, and `MonadError`. These instances allow you to compose asynchronous code as easily as `Eff`, as well as interop with existing `Eff` code. | ||
The library contains instances for `Semigroup`, `Monoid`, `Apply`, | ||
`Applicative`, `Bind`, `Monad`, `Alt`, `Plus`, `MonadEff`, and `MonadError`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth mentioning Parallel
here too? Or perhaps just "and others" if you'd rather reserve the mention of that for the section below.
README.md
Outdated
|
||
If you're building your own library, or you have to interact with some native code that expects callbacks, then *purescript-aff* provides a `makeAff` function: | ||
If you're building your own library, then *purescript-aff* provides a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually put library names in backticks rather than making them italic I think. Perhaps we can reword it generally to avoid mentioning the library though, since it seems a bit redundant when you're already reading the readme.
README.md
Outdated
All purely synchronous computations (`Eff`) can be lifted to asynchronous computations with `liftEff` defined in `Control.Monad.Eff.Class` (see [here](https://github.com/purescript/purescript-eff)). | ||
All purely synchronous computations (`Eff`) can be lifted to asynchronous | ||
computations with `liftEff` defined in `Control.Monad.Eff.Class` (see | ||
[here](https://github.com/purescript/purescript-eff)). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May as well move the link ref onto the class name (rather than linking with a here) while we're doing these updates!
README.md
Outdated
delay (Milliseconds 50.0) | ||
putVar v 1.0 | ||
a <- takeVar v | ||
log ("Succeeded with " <> show a) | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth briefly mentioning the take/put, etc. sematics AVar
blocking here? If people aren't familiar with MVar
it might not be obvious what the difference between this and a Ref
is, even with the code example.
All the new changes to the readme LGTM! |
Edits made, with slightly more explanatory avar stuff. |
@natefaubion Yes, let's merge and do a pre-release as well. |
🎉 |
🎆 🍾 🎈 |
This is a PR to rewrite the internals of
Aff
to be faster and have actual guarantees around cancellation and finalization. There's still a lot to do, but I wanted to go ahead and get some feedback on the implementation.Closes #97
Closes #96
Fixes #104
Fixes #95
Fixes #94
Fixes #91
Fixes #18