Skip to content

Add mapAsync #96

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 6 commits into from
Apr 29, 2025
Merged

Add mapAsync #96

merged 6 commits into from
Apr 29, 2025

Conversation

zyla
Copy link
Collaborator

@zyla zyla commented Dec 11, 2023

Asynchronous version of map, for easily integrating e.g. network requests into a FRP computation.

data AsyncComputation a = Sync a | Async (Aff a)

data AsyncState a
  = InProgress (Maybe (Either Error a))
  | Finished (Either Error a)

-- | Map a possibly-asynchronous function over a Dynamic.
-- |
-- | When the source dynamic changes, the mapping function is re-evaluated. If it returns `Sync`,
-- | this works like `map` - the change is propagated in the same cycle.
-- |
-- | If it returns `Async`, then the dynamic will first transition to `InProgress` and start the async computation.
-- | After it finished, it will transition to `Finished` (which might contain an error).
mapAsync :: forall a b. (a -> I.AsyncComputation b) -> Dynamic a -> Dynamic (I.AsyncState b)

zyla added 3 commits December 11, 2023 10:56

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@zyla zyla requested review from kozak and jborkowski April 23, 2025 16:15
Copy link
Contributor

@kozak kozak left a comment

Choose a reason for hiding this comment

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

LG.

pure unit
Running fiber ->
launchAff_ do
killFiber (error "Cancelled") fiber
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
killFiber (error "Cancelled") fiber
killFiber cancelledError fiber

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch. But I wonder why tests didn't catch it.

Copy link
Contributor

Choose a reason for hiding this comment

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

There are no tests for cancel I think.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No direct test, but this one should cancel the task internally

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right, mapAsync doesn't call cancel, only run which calls killFiber directly. So this function is unnecessary

zyla added 2 commits April 28, 2025 09:48
@zyla zyla merged commit 4ac328f into master Apr 29, 2025
2 checks passed
zyla added a commit that referenced this pull request May 3, 2025
* Add mapAsync

* Doc comment

* Remove warning

* Remove unnecessary code
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

Successfully merging this pull request may close these issues.

None yet

3 participants