Class: QuackConcurrency::Waiter

Inherits:
ConcurrencyTool show all
Defined in:
lib/quack_concurrency/waiter.rb

Instance Method Summary collapse

Methods inherited from ConcurrencyTool

#setup_duck_types

Constructor Details

#initialize(duck_types: nil) ⇒ Waiter

Creates a new QuackConcurrency::Waiter concurrency tool.

Parameters:

  • duck_types (Hash) (defaults to: nil)

    hash of core Ruby classes to overload. If a Hash is given, the keys :condition_variable and :mutex must be present.



8
9
10
# File 'lib/quack_concurrency/waiter.rb', line 8

def initialize(duck_types: nil)
  @queue = Queue.new(duck_types: duck_types)
end

Instance Method Details

#resume(value = nil) ⇒ void

This method returns an undefined value.

Resumes next waiting thread.

Parameters:

  • value (defaults to: nil)

    value to pass to waiting thread



15
16
17
18
# File 'lib/quack_concurrency/waiter.rb', line 15

def resume(value = nil)
  @queue << value
  nil
end

#waitObject

Note:

Will block until resumed.

Waits for another thread to resume the calling thread.

Returns:

  • value passed from resuming thread



23
24
25
# File 'lib/quack_concurrency/waiter.rb', line 23

def wait
  @queue.pop
end