Skip to content
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

println and Failed to push! #153

Open
rand5 opened this issue Aug 10, 2017 · 4 comments
Open

println and Failed to push! #153

rand5 opened this issue Aug 10, 2017 · 4 comments

Comments

@rand5
Copy link

rand5 commented Aug 10, 2017

I have a bit of code composed of a call to foreach(signal(A)) do.... Inside this there is a simple call to another function. If I include a println statement at the end of the foreach block, it executes fine, however if I remove the println statement I get,

Failed to push!
    nothing
to node
    4773: "input-1526" = nothing Void (active)

error at node: 4793: "map(input-1526)" = nothing Void (active)
MethodError: Cannot `convert` an object of type Dierckx.Spline2D to an object of type Void
This may have arisen from a call to the constructor Void(...),
since type constructors fall back to convert methods.
 in set_value! at C:\Users\Cm7045\.julia\v0.5\Reactive\src\core.jl:197 [inlined]
 in (::Reactive.##43#44{##4140#4161{Reactive.Signal{Array{ColorTypes.Gray{Float64},2}}},Reactive.Signal{Void},Tuple{Reactive.Signal{Void}}})() at C:\Users\Cm7045\.julia\v0.5\Reactive\src\operators.jl:39
 in foreach(::Reactive.#runaction, ::Array{Function,1}) at .\abstractarray.jl:1553
 in run_node(::Reactive.Signal{Void}) at C:\Users\Cm7045\.julia\v0.5\Reactive\src\core.jl:311
 in run_push(::Reactive.Signal{Void}, ::Void, ::Reactive.#print_error, ::Bool) at C:\Users\Cm7045\.julia\v0.5\Reactive\src\core.jl:329
 in run_push(::Reactive.Signal{Void}, ::Void, ::Function) at C:\Users\Cm7045\.julia\v0.5\Reactive\src\core.jl:316
 in run(::Int64) at C:\Users\Cm7045\.julia\v0.5\Reactive\src\core.jl:276
 in (::Reactive.##33#37)() at .\task.jl:360
@rand5
Copy link
Author

rand5 commented Aug 10, 2017

I am just now reading

foreach should be used instead of map when the results of f are not needed

from the docs, here,
but it seems like the behavior is not consistent, since I have other instances where I call foreach on a signal and have a return value...

@JobJob
Copy link
Member

JobJob commented Aug 10, 2017

That error message sucks and needs to be fixed - it's happening because the signal is of a specific type and you're pushing (or it gets updated to) a value of a different type. The error message is very unintuitive.

Not 100% sure but probably with the initial value of your input, your map block/function was returning nothing, then with a new value it returned a Dierckx.Spline2D. With println on the last line, which returns nothing, there is no issue.

Asides:
Also should prob change node to Signal in that error message

Note the numbers aren't line numbers they're the signal's id.

@JobJob JobJob closed this as completed Aug 10, 2017
@JobJob JobJob reopened this Aug 10, 2017
@rand5
Copy link
Author

rand5 commented Aug 10, 2017

@JobJob , your theory about the reason for the error is spot on. After reading your comment though it wasn't initially clear how to solve the problem, so I put together the following toy example that replicates the issue.

B = button(label="Get Random Number)
display.([B])
MyNumber = foreach(signal(B),init=nothing) do a
    n = rand(1)
    return n
end

My underlying use case is that I am generating data, then using a button to trigger a computation. I would then like to be able to view the computation results before deciding whether or not to export them.

After looking at the above example for a while, I realize I am abusing the language. If anyone else happens to come across this same problem, the solution I found is to define the MyNumber variable as a signal prior to the foreach(...), then push! to update its value within the foreach(...) call as opposed to upon return of the value. The corrected toy example should be something more along the lines of:

B = button(label="Get Random Number")
display.([B])
MyNumber = Signal([2.])
foreach(signal(B),init=nothing) do a
    push!(MyNumber,rand(1))
end

@JobJob
Copy link
Member

JobJob commented Aug 11, 2017

If you want your signal to have value nothing (initially with the init=nothing) and then a Float64 (after you click the button), you can just do it as:

B = button(label="Get Random Array")
display.([B])
MyNumber = map(signal(B),init=nothing, typ=Union{Void, Array{Float64}}) do a
    n = rand(1)
    return n
end

alternately you could just use typ=Any or look into Nullables in the Julia docs.

Alternately it might make more sense to just set your init=Array{Float64}() - an empty array - then the Signal's type will stay consistent.

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

No branches or pull requests

2 participants