-
Notifications
You must be signed in to change notification settings - Fork 67
README Effect and Aff #211
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,20 @@ main = launchAff_ do | |
log response.body | ||
``` | ||
|
||
## Effect and Aff | ||
|
||
`Effect` is a synchronous effect monad. It is used to sequence effectful foreign (JavaScript) code — things like random number generation, reading and writing mutable values, writing to the console and throwing and catching exceptions.[<sup>1</sup>](https://stackoverflow.com/questions/37661391/what-are-eff-and-aff) | ||
|
||
`Aff` is an asynchronous effect monad. It can handle and sequence effectful asynchronous code, like AJAX requests, timeouts, and network and file IO. | ||
It also provides a nice mechanism for handling errors. | ||
|
||
Furthermore, `Aff` can perform synchronous effects by using `liftEffect`. In other words, `Effect` is a special case of `Aff`, for the special case that we expect the effect to complete immediately. `Effect` is in the core libraries instead of `Aff` for two reasons. | ||
|
||
1. The implementation of `Effect` is much simpler than `Aff`, which makes a big difference for non-JavaScript backends. | ||
2. `Effect` is much faster than `Aff`, and we expect most effects to complete synchronously, so usually `Effect` will suffice. | ||
|
||
|
||
Many I/O-related packages in the PureScript ecosystem provide both an asynchronous callback-based `Effect` API and an `Aff` API for the same feature. When you encounter this, you should almost always prefer the `Aff` API. You will find the `Aff` API is much simpler to use correctly. | ||
|
||
## Documentation | ||
|
||
`aff` documentation is stored in a few places: | ||
|
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.
I know we have Affjax, but AJAX is just not a term that is used anymore. I think we should keep it in the early 2000s 😄.
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.
lol ok
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.
Done.