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

Functional form sending Nothing to channel #5

Open
mosiman opened this issue Jan 1, 2022 · 1 comment
Open

Functional form sending Nothing to channel #5

mosiman opened this issue Jan 1, 2022 · 1 comment

Comments

@mosiman
Copy link

mosiman commented Jan 1, 2022

Hi, thanks for the library! I'm not sure if you're still maintaining this, but if you are, I've noticed what seems to be a problem with the function version of @select.

A somewhat minimal script below reproduces to problem for me:

using Select
ch1 = Channel{Int64}()
ch2 = Channel{Float64}()
@async begin
    for i in 1:10
        put!(ch1, i)
        sleep(1)
    end
end
@async begin
    for i in 1:10
        put!(ch2, i * 1.0)
        sleep(1)
    end
end

# Switch the order -- the second clause seems to always receive nothing.
clauses = [(:take, ch1), (:take, ch2)]
# clauses = [(:take, ch2), (:take, ch1)]
while true
    idx, val = Select.select(clauses)
    println("Received value of type $(typeof(val))")
end

# The macro form always works, though
# while true
#     @select begin
#         ch1 |> val => println("Received value of type $(typeof(val))")
#         ch2 |> val => println("Received value of type $(typeof(val))")
#     end
# end

If I run this, I get this error

Received value of type Int64
ERROR: LoadError: TypeError: in typeassert, expected Float64, got a value of type Nothing

It always seems to be sending nothing to the second channel, though. If you switch the order of the clauses, I get

Received value of type Float64
ERROR: LoadError: TypeError: in typeassert, expected Int64, got a value of type Nothing

The macro always seems to work, though!

I realize this library is one of many attempts to get this go-like select statements into the standard library (or core?) so if you've moved on from this, all good! I've tried to read up on the source to understand what was going on and to provide a fix, but it's a bit more than I can chew at the moment.

@NHDaly
Copy link
Owner

NHDaly commented Feb 4, 2022

👍 Thanks! Yeah, unfortunately this package is dead. @Vtjnash and others in this thread: JuliaLang/julia#13763 have pointed out that @select as a concurrency primitive has a number of issues, and that it would be better for user code to avoid it.

So far I have found that I'm actually able to write decent programs without it, usually using a Channel instead...

So yeah, this was only ever an experiment, and we aren't using it at all 👍 i'll add a note to the README to hopefully make that clearer!

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