Revision 468f09746ae14ebd023500d62815c964e239aeda authored by Jeff Bezanson on 17 January 2018, 19:36:30 UTC, committed by Jeff Bezanson on 17 January 2018, 19:43:01 UTC
1 parent 78bc9c8
dictchannel.jl
# This file is a part of Julia. License is MIT: https://julialang.org/license
import Base: put!, wait, isready, take!, fetch
mutable struct DictChannel <: AbstractChannel
d::Dict
cond_take::Condition # waiting for data to become available
DictChannel() = new(Dict(), Condition())
end
function put!(D::DictChannel, k, v)
D.d[k] = v
notify(D.cond_take)
D
end
function take!(D::DictChannel, k)
v=fetch(D,k)
delete!(D.d, k)
v
end
isready(D::DictChannel) = length(D.d) > 1
isready(D::DictChannel, k) = haskey(D.d,k)
function fetch(D::DictChannel, k)
wait(D,k)
D.d[k]
end
function wait(D::DictChannel, k)
while !isready(D, k)
wait(D.cond_take)
end
end
Computing file changes ...