JuliaGizmos / Reactive.jl

Reactive programming primitives for Julia
http://juliagizmos.github.io/Reactive.jl/
Other
182 stars 46 forks source link

Please implement pull / push model in asynchronous way #127

Open yuehhua opened 7 years ago

yuehhua commented 7 years ago

I have found several issues (#103, #104, #99, #82), they are talking about the same thing.

The asynchronous pull / push model

Have you read the ReactiveX? If not, please take some time to read it.

I would provide some solutions to these issues.

103 mentioned the pull / push model directly, and the lazy evaluation can be achieved.

Lazy evaluation, is an important property in functional programming. On top of functional programming, reactive programming surely is. With this, one can assign the whole pipeline to some scheduler, e.g. process scheduler, to achieve concurrency.

104, the reactive programming is based on the pull / push model, then the signals are generated in demand.

Utilizing the property of Task, the operations can be plugable, because the operations wrapped in Task are independent to each other, then one can rearrange the operations as needed. Task keeps the function or operation in it. When the data is not pull (or push) to the Task, the data stream stops.

99 The pull / push model, is similar to signal / slot pattern.

If the operations are plugable, then signal / slot pattern is easy to achieve. With signal / slot pattern, website data binding and graphic user interface would be easy to implement. We can even make a package like D3.js, and a good data binding contributes a lot.

82 is the basic of Task.

About one year ago, it's the timing this package emerged, I have used and studied the documentation. I found that this may not implemented in asynchronous way and I was disappointed then. When I getting into the reactive programming and functional programming, I realize the power of asynchronous, and it should be BRING TO JULIA. Further, I found that ReactiveX is the one I pursued......no, it can be more powerful. The basic of concurrency programming is Task (or coroutine). Reactive programming can make data processing, web animation, and GUI easy. So, I make my own one, ReactiveExtensions.jl, in order to bring ReactiveX to julia.

But there are still some necessary features not implemented:

Finally, I suggest you to add pull / push model into this package and my package provides as an example.

yuehhua commented 7 years ago

Additionally, the kernel of operating system can be made based on this. ref. An Introduction to Python Concurrency

timholy commented 7 years ago

push! is asynchronous. Try the following by includeing it from a script:

using Reactive, Base.Test
s = Signal(3)
push!(s, 4)
@test value(s) == 3   # note it's not 4 yet
yield()
@test value(s) == 4
timholy commented 7 years ago

Check out the source code and see how the message queue is handled.

yuehhua commented 7 years ago

I will check it in detail.

yuehhua commented 7 years ago

I tried:

julia> using Reactive

julia> a = Signal(0)
Signal{Int64}(0, nactions=0)

julia> value(a)
0

julia> push!(a, 42)

julia> a
Signal{Int64}(42, nactions=0)

julia> value(a)
42

julia> b = map(x -> x+5, a)
Signal{Int64}(47, nactions=0)

julia> value(b)
47

The operations are performed before I value it.

timholy commented 7 years ago

That's because you're running it interactively, and the command prompt yields; this gives Reactive time to run its task and empty the message queue. Try running it from a script.

yuehhua commented 7 years ago

script:

using Reactive
a = Signal(0)
println("a:", a)
println("a:", value(a))

push!(a, 42)
println("a:", a)
println("a:", value(a))

result:

a:Signal{Int64}(0, nactions=0)
a:0
a:Signal{Int64}(42, nactions=0)
a:42

The same?

timholy commented 7 years ago

println yields to other tasks, too. Did you try the version I pasted? It definitely proves that this is asynchronous...as does looking at the source code.

yuehhua commented 7 years ago

OK, I got the expected answer. It is surely asynchronous.

shashi commented 7 years ago

Hi @yuehhua I hope your concerns were addressed thanks to @timholy's comments! If not, can you clarify which of them are still not?

Thanks! (Sorry for checking in late here.)