aqzas
7/5/2019 - 5:02 AM

Channel

Channel

c1 = Channel(32)
c2 = Channel(32)

# Channel{T}(sz) T is type, if T is null, the channel could contain any type, sz is the maximum number in Channle, push!() will wait if the channel is full

# and a function `foo` which reads items from c1, processes the item read
# and writes a result to c2,
function foo()
    while true
        data = take!(c1)
        [...]               # process data
        put!(c2, result)    # write out result
    end
end

# we can schedule `n` instances of `foo` to be active concurrently.
for _ in 1:n
    @async foo()
end