Class: Raktr::Tasks

Inherits:
Object
  • Object
show all
Includes:
Mutex_m
Defined in:
lib/raktr/tasks.rb,
lib/raktr/tasks/base.rb,
lib/raktr/tasks/delayed.rb,
lib/raktr/tasks/one_off.rb,
lib/raktr/tasks/periodic.rb,
lib/raktr/tasks/persistent.rb

Overview

Task list.

Author:

Defined Under Namespace

Classes: Base, Delayed, OneOff, Periodic, Persistent

Instance Method Summary collapse

Constructor Details

#initializeTasks

Returns a new instance of Tasks.



25
26
27
28
29
# File 'lib/raktr/tasks.rb', line 25

def initialize
    super

    @tasks = []
end

Instance Method Details

#<<(task) ⇒ Tasks

Note:

Only unique tasks will be included.

Note:

Will assign ‘self` as the task’s owner.

Returns ‘self`.

Parameters:

  • task (Base)

    Task to add to the list.

Returns:



37
38
39
40
41
42
43
44
# File 'lib/raktr/tasks.rb', line 37

def <<( task )
    synchronize do
        task.owner = self
        @tasks << task
    end

    self
end

#any?Bool

Returns:

  • (Bool)


76
77
78
# File 'lib/raktr/tasks.rb', line 76

def any?
    !empty?
end

#call(*args) ⇒ Tasks

Calls all tasks.

Returns:



94
95
96
97
# File 'lib/raktr/tasks.rb', line 94

def call( *args )
    @tasks.dup.each { |t| t.call *args }
    self
end

#clearTasks

Removes all tasks.

Returns:



83
84
85
86
87
88
89
# File 'lib/raktr/tasks.rb', line 83

def clear
    synchronize do
        @tasks.clear
    end

    self
end

#delete(task) ⇒ Base?

Returns The task if it was included, ‘nil` otherwise.

Parameters:

  • task (Base)

    Task to remove from the list.

Returns:

  • (Base, nil)

    The task if it was included, ‘nil` otherwise.



57
58
59
60
61
62
63
# File 'lib/raktr/tasks.rb', line 57

def delete( task )
    synchronize do
        task = @tasks.delete( task )
        task.owner = nil if task
        task
    end
end

#empty?Bool

Returns:

  • (Bool)


71
72
73
# File 'lib/raktr/tasks.rb', line 71

def empty?
    @tasks.empty?
end

#hashObject



99
100
101
# File 'lib/raktr/tasks.rb', line 99

def hash
    @tasks.hash
end

#include?(task) ⇒ Bool

Parameters:

  • task (Base)

    Task to check.

Returns:

  • (Bool)


49
50
51
# File 'lib/raktr/tasks.rb', line 49

def include?( task )
    @tasks.include? task
end

#sizeInteger

Returns:

  • (Integer)


66
67
68
# File 'lib/raktr/tasks.rb', line 66

def size
    @tasks.size
end