Class: JsTestServer::Server::Resources::RemoteControl::Queue

Inherits:
Object
  • Object
show all
Defined in:
lib/js_test_server/server/resources/remote_control.rb

Instance Method Summary collapse

Constructor Details

#initializeQueue

Returns a new instance of Queue.



6
7
8
9
# File 'lib/js_test_server/server/resources/remote_control.rb', line 6

def initialize
  @items = []
  @subscriber = nil
end

Instance Method Details

#clearObject



22
23
24
25
# File 'lib/js_test_server/server/resources/remote_control.rb', line 22

def clear
  items, @items = @items, []
  items
end

#push(item) ⇒ Object Also known as: <<



10
11
12
13
# File 'lib/js_test_server/server/resources/remote_control.rb', line 10

def push item
  @items << item
  notify_subscriber if @subscriber
end

#subscribe(&blk) ⇒ Object



15
16
17
18
# File 'lib/js_test_server/server/resources/remote_control.rb', line 15

def subscribe &blk
  @subscriber = blk
  notify_subscriber unless @items.empty?
end

#to_aObject



26
27
28
# File 'lib/js_test_server/server/resources/remote_control.rb', line 26

def to_a
  @items
end

#unsubscribeObject



19
20
21
# File 'lib/js_test_server/server/resources/remote_control.rb', line 19

def unsubscribe
  @subscriber = nil
end