We have an existing code base that relies on Channel#full? and Channel#empty? but those methods are gone in 0.31.0. For example, in one part of the code we only want to fsync a file when the incoming queue is empty:
loop do
file.write_bytes ch.receive
file.fsync if ch.empty?
end
Is there a technical difficulty to re-implement the methods? Or do any one have suggestions on how to work around that?
class Channel(T)
def full?
if queue = @queue
return queue.size >= @capacity
end
!@senders.empty?
end
def empty?
if queue = @queue
return queue.empty?
end
@senders.empty?
end
end
But others have pointed out that it’s not thread safe.