-
Notifications
You must be signed in to change notification settings - Fork 32
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
listeners as Vector{WeakRef} #1
Comments
As a purely technical solution, I guess we could have But it's an interesting problem. One doesn't mind holding on to the functions, it's the derived Observables you'd rather not hold. I wonder if |
Good idea! It would help if someone wants to use |
IMO the GC management is one of the less intuitive things about Reactive. If you don't mind, I'll spend a little time to see if I can design something that might make it simpler for the user. Most likely, there will be some cost in making the internals a little more complex 😦 |
I agree that this is the least intuitive part of Reactive. It does come in handy though. Yes, you're welcome to tackle this! Hopefully it won't make things too complex. |
OK, check out this gist: https://gist.github.com/timholy/eb224bce573e37b31456eed789bb8f37 The basic idea is that one can define actions that don't create a new Observable ( I made EDIT: I should add that of course this may have serious flaws (it needs much more stringent testing), but at least it hopefully illustrates one possible direction for making working with Observables (and defining actions on them) a little bit more like "regular" julia rules: variables are GCed, functions are not. |
@timholy Very interesting! Thanks for putting this together! I like the distinction created by I will have to take a more detailed look when I'm not this (very) sleepy. 😅 |
Awesome. This looks quite good! The only concern I have is this julia> function inc!(x)
global counter
counter::Int += 1
end
inc! (generic function with 1 method)
julia> o = Obs.Observable(0);
julia> Obs.trigger(inc!, o);
julia> o[] = 1
1
julia> counter
1
julia> o[] = 1
1
julia> counter
1
julia> o[] = 2
2
julia> counter
2 I'd expect the counter to go 1,2,3... no matter what updates it got (imagine counting the number of mouse clicks) Besides it's quite easy to still have a cycle: julia> o = Obs.Observable(0.);
julia> Obs.trigger(evil, o);
julia> o = Obs.Observable(0.);
julia> evil(x) = o[] = rand();
julia> Obs.trigger(evil, o);
julia> o[]=1.0
ERROR: StackOverflowError:
in setindex!(::Obs.Observable{Float64}, ::Float64) at /home/shashi/code/observable.jl:85
in evil(::Float64) at ./REPL[13]:1
in setindex!(::Obs.Observable{Float64}, ::Float64) at /home/shashi/code/observable.jl:85
in evil(::Float64) at ./REPL[13]:1
in setindex!(::Obs.Observable{Float64}, ::Float64) at /home/shashi/code/observable.jl:85
in evil(::Float64) at ./REPL[13]:1
in setindex!(::Obs.Observable{Float64}, ::Float64) at /home/shashi/code/observable.jl:85
... Also, are you not a fan of the name |
True, that cycle detection isn't perfect, we could leave it out and reconsider if it becomes a problem. And actually, I do like I'm not certain that I have all the memory-management stuff correct. In particular, a multi-argument action should be removed if even one of the observables gets GCed, and I'm not certain I got that part right. But if you like this overall, I could turn it into a PR. |
One other issue is that, while I'm a fan of synchronous execution by default, we should come up with a scheme that allows users to schedule asynchronously when desired. |
Would It's easy to do
I'm not sure if that's the correct thing expected by a casual user. But it seems like this does happen currently? Sure! It would be good to turn this into a PR. |
I'm experimenting with creating a discrete event simulation package EDIT: I guess this isn't the current state but a proposal. Sorry for |
Bump, why storing listening |
I think this issue is too old to be useful. Feel free to open a new issue. The main feature of any proposal would have to be
I'm actually not sure that this can be fixed in a way that satisfies 1. |
My concern with using
Vector{WeakRef}
is, inthe handler goes out of scope when the function finishes.
ping @timholy
The text was updated successfully, but these errors were encountered: