-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Channel constructor requires an explicit size. Also implements 0-sized channels #18832
Conversation
7a24ca1
to
6d7b960
Compare
put!(c,v,Val{c.sz_max==0}) | ||
end | ||
|
||
function put!(c::Channel, v, ::Type{Val{false}}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add some comments about what this new Val argument is differentiating?
@@ -1437,10 +1437,16 @@ endof | |||
Constructs a `Channel` that can hold a maximum of `sz` objects of type `T`. `put!` calls on | |||
a full channel block till an object is removed with `take!`. | |||
|
|||
`Channel(0)` constructs a Channel without a backing store. Consequently a `put!` on a | |||
0-sized channel will block till another task calls a `take!` on it. And vice-versa. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"block until"
`Channel(0)` constructs a Channel without a backing store. Consequently a `put!` on a | ||
0-sized channel will block till another task calls a `take!` on it. And vice-versa. | ||
|
||
`isready` on a 0-sized channel returns true if there are any tasks blocked on a `put!` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be separated with either a period or another line between this and the following statement
d2f385f
to
6d5d12e
Compare
@tkelman thanks for the feedback. Have pushed a commit that makes the arguments self-explanatory and also updated the docs. |
several more cases of "block till" would be better as "block until" I think |
@StefanKarpinski your thoughts?
|
Yes, in general this is good. A couple of high-level things. It feels like Is all the |
In this case, the dispatch on values was mainly for style and readability. Will capture it in the type or replace with if/else. |
Updated. |
8b450d9
to
903c464
Compare
Deprecated Will squash and merge in a couple of days if there are no more comments. |
|
||
# deprecated empty constructor | ||
function Channel() | ||
depwarn(string("The empty constructor Channel() is deprecated. ", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why isn't this in deprecated.jl
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Channel{T}()
constructor needs to be inside the type definition, while Channel()
which is equivalent of Channel{Any}()
can be outside. Thus added both in channels.jl itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why can't it be an outer constructor? especially with two different signatures in different places that should be removed, those comments are going to be easy to miss
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How?
Channel() = Channel{Any}(32)
is fine.
Channel{T}() = Channel{T}(32)
is not callable.
julia> type Foo{T}
foo::T
end
julia> Foo{T}() = Foo{T}(1)
WARNING: static parameter T does not occur in signature for Type at REPL[2]:1.
The method will not be callable.
Foo{T}
Move channel tests into its own file. Implement 0-sized channels.
903c464
to
e23f4e2
Compare
@tkelman AV error is unrelated and OSX build is not starting up at all. Should I restart the build? |
As discussed in #17698 (comment), the default channel size of 32 has been removed. The size needs to be specified explicitly.
Channel(Inf)
is an unlimited channel, a shorter way of writingChannel(typemax(UInt))
Channel tests have been moved into its own file.
Added support for 0-sized channels (as mentioned in #17699). This provides the same behavior as
produce
/consume
which can be deprecated in a separate PR.