Class: Going::Operation

Inherits:
Object
  • Object
show all
Extended by:
BooleanAttrReader
Defined in:
lib/going/operation.rb

Direct Known Subclasses

Push, Shift

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BooleanAttrReader

battr_reader

Constructor Details

#initialize(opts = {}, &on_complete) ⇒ Operation

Returns a new instance of Operation.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/going/operation.rb', line 8

def initialize(opts = {}, &on_complete)
  @message = opts[:message]
  @select_statement = opts[:select_statement]
  @on_complete = on_complete

  @completed = false
  @closed = false
  @signaled = false

  @semaphore = ConditionVariable.new
end

Instance Attribute Details

#messageObject

Returns the value of attribute message.



5
6
7
# File 'lib/going/operation.rb', line 5

def message
  @message
end

#select_statementObject (readonly)

Returns the value of attribute select_statement.



6
7
8
# File 'lib/going/operation.rb', line 6

def select_statement
  @select_statement
end

Instance Method Details

#closeObject



34
35
36
37
# File 'lib/going/operation.rb', line 34

def close
  @closed = true
  signal
end

#completeObject



29
30
31
32
# File 'lib/going/operation.rb', line 29

def complete
  @completed = true
  signal
end

#incomplete?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/going/operation.rb', line 39

def incomplete?
  !completed?
end

#signalObject



24
25
26
27
# File 'lib/going/operation.rb', line 24

def signal
  @signaled = true
  semaphore.signal
end

#wait(mutex) ⇒ Object



20
21
22
# File 'lib/going/operation.rb', line 20

def wait(mutex)
  semaphore.wait(mutex) until wake?
end