lib/async/channel.rb in async-tools-0.1.2 vs lib/async/channel.rb in async-tools-0.1.3
- old
+ new
@@ -1,10 +1,8 @@
# frozen_string_literal: true
class Async::Channel
- extend Forwardable
-
attr_reader :subscribers
class Error < StandardError; end
class ChannelClosedError < Error; end
@@ -15,13 +13,21 @@
@parent = options[:parent]
@closed = false
end
- def_delegators :@queue, :count, :empty?, :length, :size, :full?
- def_delegator :self, :enqueue, :<<
+ def count = @queue.count
+ def length = @queue.length
+ def size = @queue.size
+ def full? = @queue.full?
+ def empty? = @queue.empty?
+ def closed? = @closed
+ def open? = !closed?
+
+ def <<(item) = enqueue(item)
+
def enqueue(message)
check_channel_writeable!
@queue << [:message, message]
end
@@ -44,17 +50,9 @@
@queue.expand(@subscribers)
@subscribers.times do
@queue << [:close]
end
- end
-
- def closed?
- @closed
- end
-
- def open?
- !closed?
end
def dequeue
check_channel_readable!