File tree 2 files changed +13
-2
lines changed
2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ Representation of a channel passing objects of type `T`.
8
8
abstract type AbstractChannel{T} end
9
9
10
10
"""
11
- Channel{T}(sz::Int)
11
+ Channel{T}(sz::Int=0 )
12
12
13
13
Constructs a `Channel` with an internal buffer that can hold a maximum of `sz` objects
14
14
of type `T`.
@@ -19,8 +19,12 @@ And vice-versa.
19
19
20
20
Other constructors:
21
21
22
+ * `Channel()`: default constructor, equivalent to `Channel{Any}(0)`
22
23
* `Channel(Inf)`: equivalent to `Channel{Any}(typemax(Int))`
23
24
* `Channel(sz)`: equivalent to `Channel{Any}(sz)`
25
+
26
+ !!! compat "Julia 1.3"
27
+ The default constructor `Channel()` was added in Julia 1.3.
24
28
"""
25
29
mutable struct Channel{T} <: AbstractChannel{T}
26
30
cond_take:: Threads.Condition # waiting for data to become available
@@ -48,6 +52,7 @@ function Channel{T}(sz::Float64) where T
48
52
return Channel {T} (sz)
49
53
end
50
54
Channel (sz) = Channel {Any} (sz)
55
+ Channel () = Channel {Any} (0 )
51
56
52
57
# special constructors
53
58
"""
Original file line number Diff line number Diff line change @@ -13,6 +13,9 @@ using Random
13
13
end
14
14
15
15
@testset " various constructors" begin
16
+ c = Channel ()
17
+ @test eltype (c) == Any
18
+
16
19
c = Channel (1 )
17
20
@test eltype (c) == Any
18
21
@test put! (c, 1 ) == 1
31
34
tvals = Int[take! (c) for i in 1 : 10 ^ 6 ]
32
35
@test pvals == tvals
33
36
34
- @test_throws MethodError Channel ()
35
37
@test_throws ArgumentError Channel (- 1 )
36
38
@test_throws InexactError Channel (1.5 )
37
39
end
48
50
@test c. sz_max == 0
49
51
@test collect (c) == 1 : 100
50
52
53
+ c = Channel () do c; put! (1 ); put! (" hi" ) end
54
+ @test c. sz_max == 0
55
+ @test collect (c) == [1 , " hi" ]
56
+
51
57
c = Channel {Int} (Inf ) do c; put! (c,1 ); end
52
58
@test eltype (c) == Int
53
59
@test c. sz_max == typemax (Int)
You can’t perform that action at this time.
0 commit comments