Class: Mongo::TimeoutThread

Inherits:
Object show all
Defined in:
lib/jmongo/mongo/utils.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, doc, timeout) ⇒ TimeoutThread

Returns a new instance of TimeoutThread.



7
8
9
10
11
12
13
# File 'lib/jmongo/mongo/utils.rb', line 7

def initialize(collection, doc, timeout)
  @collection = collection
  @doc = doc
  @timeout = timeout
  @queue = SizedQueue.new(1)
  spawn_thread
end

Instance Attribute Details

#threadObject (readonly)

Returns the value of attribute thread.



6
7
8
# File 'lib/jmongo/mongo/utils.rb', line 6

def thread
  @thread
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



6
7
8
# File 'lib/jmongo/mongo/utils.rb', line 6

def timeout
  @timeout
end

Instance Method Details

#cancelObject



19
20
21
22
# File 'lib/jmongo/mongo/utils.rb', line 19

def cancel
  return if @thread[:cancel]
  @thread[:cancel] = true
end

#stopObject



24
25
26
# File 'lib/jmongo/mongo/utils.rb', line 24

def stop
  @queue.push false
end

#triggerObject



15
16
17
# File 'lib/jmongo/mongo/utils.rb', line 15

def trigger
  @queue.push(true) if @queue.length == 0
end