Skip to content

Commit 18a80ae

Browse files
committed
Add Channel{Int}() constructor, default to sz=0
1 parent d5cad74 commit 18a80ae

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

base/channels.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Other constructors:
2424
* `Channel(sz)`: equivalent to `Channel{Any}(sz)`
2525
2626
!!! compat "Julia 1.3"
27-
The default constructor `Channel()` was added in Julia 1.3.
27+
The default constructor `Channel()` and default `sz=0` were added in Julia 1.3.
2828
"""
2929
mutable struct Channel{T} <: AbstractChannel{T}
3030
cond_take::Threads.Condition # waiting for data to become available
@@ -36,7 +36,7 @@ mutable struct Channel{T} <: AbstractChannel{T}
3636
data::Vector{T}
3737
sz_max::Int # maximum size of channel
3838

39-
function Channel{T}(sz::Integer) where T
39+
function Channel{T}(sz::Integer = 0) where T
4040
if sz < 0
4141
throw(ArgumentError("Channel size must be either 0, a positive integer or Inf"))
4242
end

test/channels.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ end
1515
@testset "various constructors" begin
1616
c = Channel()
1717
@test eltype(c) == Any
18+
@test c.sz_max == 0
1819

1920
c = Channel(1)
2021
@test eltype(c) == Any
@@ -28,6 +29,10 @@ end
2829
@test eltype(c) == Int
2930
@test_throws MethodError put!(c, "Hello")
3031

32+
c = Channel{Int}()
33+
@test eltype(c) == Int
34+
@test c.sz_max == 0
35+
3136
c = Channel{Int}(Inf)
3237
@test eltype(c) == Int
3338
pvals = map(i->put!(c,i), 1:10^6)

0 commit comments

Comments
 (0)