Capturing effectful callbacks in an Effect #95
Unanswered
thomasmarsh
asked this question in
Q&A
Replies: 1 comment
-
Hey @thomasmarsh! Sorry for missing this 😄 I think you sent it right as we were in the throes of open sourcing. Given the environment pattern, I believe that addressed your concern here, but wanted to point there for posterity. If the topic isn't completely stale to you now, I'm moving it to discussions where we can chat further! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I hit a case that I can't figure out, and for which I'm not sure there is a good answer.
If I have an effect which captures a callback,
(A -> B) -> Effect<Never>
, which will run continuously and repeatedly invoke the callback, then this functionality is now outside the reducer world.This is okay if my callback is a pure function and I write lots of tests for it. However, if the computation depends on side effects, it poses a number of problems. In particular, the callback may depend on the state from the reducer, and also any effects that it does run may need to feedback into the reducer.
The only way I see to partially rectify that is to pass a scoped store into the closure such that a
getState
andsend
function can be provided. However, not even that helps the case where the effects may be asynchronous and the closure clearly needs to provide synchronous response. That leads to thoughts about promises/futures or other more traditional concurrency toolsthat live firmly outside the reducer architecture.
We hit this in the case of a micro HTTP server that we need to host, but it is certainly a more general problem. For our case we were able to make the callback pure. If that were to change, we'd likely still model the HTTP service layer compositionally, but it would represent unattached state in our application.
Any thoughts are welcome. This is the demo code I put together to demonstrate the issue.
Beta Was this translation helpful? Give feedback.
All reactions