reflex-frp / reflex

Interactive programs without callbacks or side-effects. Functional Reactive Programming (FRP) uses composable events and time-varying values to describe interactive systems as pure functions. Just like other pure functional code, functional reactive code is easier to get right on the first try, maintain, and reuse.
https://reflex-frp.org
BSD 3-Clause "New" or "Revised" License
1.07k stars 148 forks source link

Resource management in a reflex program #428

Open expipiplus1 opened 4 years ago

expipiplus1 commented 4 years ago

I think this is at least an issue with documentation.

It's not clear from reading the examples or the manual how a reflex-frp program might deal with scarce resources, i.e. resources which must be freed promptly (not left up to a finalizer). I'd like to think that FRP would be a good fit for managing complex object lifetimes (particularly object creation when needed). On the other hand from https://github.com/reflex-frp/reflex-dom/issues/114 it looks as guaranteed destruction might be problematic with reflex.

Either way I think it might be good to at least have a footnote or something somewhere with some greppable terms related to resource management.

ryantrinkle commented 4 years ago

This is definitely something that would be nice to have. Reflex's built-in resource management is all GC-driven, so it's only appropriate for situations where prompt destruction is not required. However, we do have a system that can be leveraged for this: Adjustable. In reflex-dom, when widgets are removed from the DOM, it happens, of course, promptly. We also use this in QueryT to promptly unsubscribe from queries that we're no longer interested in.

My basic idea for this would be that a "disposable" widget provides a "disposal" routine to its parent, inside of a Behavior or a Dynamic. When the widget is removed by Adjustable, the disposal routine will be invoked. Do you think that would cover your use case?

expipiplus1 commented 4 years ago

A dynamic destructor sounds very useful, yeah. What would the story be regarding exception safety for these widgets?

On Tue, May 19, 2020, 2:12 AM Ryan Trinkle notifications@github.com wrote:

This is definitely something that would be nice to have. Reflex's built-in resource management is all GC-driven, so it's only appropriate for situations where prompt destruction is not required. However, we do have a system that can be leveraged for this: Adjustable. In reflex-dom, when widgets are removed from the DOM, it happens, of course, promptly. We also use this in QueryT to promptly unsubscribe from queries that we're no longer interested in.

My basic idea for this would be that a "disposable" widget provides a "disposal" routine to its parent, inside of a Behavior or a Dynamic. When the widget is removed by Adjustable, the disposal routine will be invoked. Do you think that would cover your use case?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/reflex-frp/reflex/issues/428#issuecomment-630350955, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGRJXACSJYNZZBW5BFZPNTRSF3ANANCNFSM4NDZQRLQ .