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)

    Add an ojbect of DRbQS::Task.

  • arg (Array)

    Add all elements of an array of objects of DRbQS::Task.



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

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.



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

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

#waitObject

Wait finishes of all tasks in queue of a server.



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

def wait
  Fiber.yield(:wait)
end