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

Please implement pull / push model in asynchronous way #127

Open
yuehhua opened this issue Mar 12, 2017 · 10 comments
Open

Please implement pull / push model in asynchronous way #127

yuehhua opened this issue Mar 12, 2017 · 10 comments

Comments

@yuehhua
Copy link

yuehhua commented Mar 12, 2017

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:

  • scheduler
  • concurrency (including easy parallelism)

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

@yuehhua
Copy link
Author

yuehhua commented Mar 12, 2017

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

@timholy
Copy link
Member

timholy commented Mar 12, 2017

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
Copy link
Member

timholy commented Mar 12, 2017

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

@yuehhua
Copy link
Author

yuehhua commented Mar 12, 2017

I will check it in detail.

@yuehhua
Copy link
Author

yuehhua commented Mar 12, 2017

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
Copy link
Member

timholy commented Mar 12, 2017

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
Copy link
Author

yuehhua commented Mar 13, 2017

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
Copy link
Member

timholy commented Mar 13, 2017

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
Copy link
Author

yuehhua commented Mar 13, 2017

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

@shashi
Copy link
Member

shashi commented Apr 9, 2017

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.)

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

3 participants