Hi,
I am learning reactive programming with the great package Rocket.jl
and have a question (pinging the lead dev @bvdmitri). A MWE of my use case to make my question explicit is shown below.
import Rocket
struct MyActor <: Rocket.Actor{Union{Char, Int}} end
function Rocket.next!(a::MyActor, c::Char)
println("got char $c, waiting ..."); flush(stdout)
sleep(1)
println("leaving char"); flush(stdout)
return nothing
end
function Rocket.next!(a::MyActor, c::Int)
println("got Int $c, waiting ..."); flush(stdout)
sleep(1)
println("leaving Int"); flush(stdout)
return nothing
end
Rocket.complete!(a::MyActor) = println("done"); flush(stdout)
intsource = Rocket.make(Int) do actor
Rocket.setTimeout(1000) do
Rocket.next!(actor, 1)
end
Rocket.setTimeout(2000) do
Rocket.next!(actor, 2)
end
Rocket.setTimeout(3000) do
Rocket.next!(actor, 3)
end
Rocket.setTimeout(5000) do
Rocket.complete!(actor)
end
end
charsource = Rocket.make(Char) do actor
Rocket.setTimeout(1000) do
Rocket.next!(actor, 'a')
end
Rocket.setTimeout(2000) do
Rocket.next!(actor, 'b')
end
Rocket.setTimeout(3000) do
Rocket.next!(actor, 'c')
end
Rocket.setTimeout(5000) do
Rocket.complete!(actor)
end
end
actor = Rocket.sync(MyActor())
Rocket.subscribe!(charsource |> Rocket.async(), actor)
Rocket.subscribe!(intsource |> Rocket.async(), actor)
yield()
wait(actor)
There is a sync
actor that is fed by multiple async
sources. In this example, the actor is fed Char
s and Int
s and elements arrive asynchronously (in my real case, these would be network events). In each of the two next!
method definitions, there is some computation that takes a bit of time.
I would expect that, once any of these two methods gets called first, the function ends before any other next!
can be called. Depending on the temporal separation of the async events, and on the duration of the computations inside the next!
methods, this might not be true. A typical output from the code above is
got char a, waiting ...
got Int 1, waiting ...
leaving char
got char b, waiting ...
leaving Int
got Int 2, waiting ...
leaving char
got char c, waiting ...
leaving Int
got Int 3, waiting ...
leaving char
leaving Int
done
while I would expect
got char a, waiting ...
leaving char
got Int 1, waiting ...
leaving Int
got char b, waiting ...
leaving char
got Int 2, waiting ...
leaving Int
got char c, waiting ...
leaving char
got Int 3, waiting ...
leaving Int
done
It is likely that I am misusing some of the package functionality, but any clarification would be appreciated.