Class: DRbQS::Task::Registrar

Inherits:
Object
  • Object
show all
Defined in:
lib/drbqs/task/registrar.rb

Overview

The object of this class is mainly used in DRbQS::Task::Generator#set and calls Fiber.yield.

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Registrar

Returns a new instance of Registrar.

Parameters:

  • data (Hash)

    Set instance variables from the hash.



7
8
9
10
11
# File 'lib/drbqs/task/registrar.rb', line 7

def initialize(data)
  data.each do |key, val|
    instance_variable_set("@#{key.to_s}", val)
  end
end

Instance Method Details

#add(arg) ⇒ Object

Add tasks to server.

Parameters:

  • arg (DRbQS::Task, Array)

    DRbQS::Task object or array of DRbQS::Task objects, which is added to pool of tasks



15
16
17
18
19
20
21
22
23
24
# File 'lib/drbqs/task/registrar.rb', line 15

def add(arg)
  case arg
  when DRbQS::Task
    Fiber.yield(arg)
  when Array
    arg.each { |t| Fiber.yield(t) }
  else
    raise ArgumentError, "An argument must be DRbQS::Task or an array of DRbQS::Task."
  end
end

#create_add(*args, &block) ⇒ Object

Create an object of DRbQS::Task and add it. The arguments are same as DRbQS::Task.



28
29
30
# File 'lib/drbqs/task/registrar.rb', line 28

def create_add(*args, &block)
  add(DRbQS::Task.new(*args, &block))
end

#waitObject

Wait finishes of all tasks in queue of a server.



33
34
35
# File 'lib/drbqs/task/registrar.rb', line 33

def wait
  Fiber.yield(:wait)
end