class RuneRb::System::Types::SortedStack
A Stack object organizes work via RuneRb::System::Types::Task
objects and ensures the sequential execution of Tasks based on their Priority.
Public Class Methods
Constructs a new Stack object @return [Stack]
# File deployment/app/system/types/stack.rb, line 7 def initialize @registry = [] end
Public Instance Methods
Removes all Tasks from the <@registry>
# File deployment/app/system/types/stack.rb, line 56 def clear @registry.clear end
Returns whether the <@registry> is empty or not via boolean values (true, false) @return [Boolean] is the <@registry> empty?
# File deployment/app/system/types/stack.rb, line 23 def empty? @registry.empty? end
Returns the first task in the <@registry> @return [RuneRb::System::Types::Task, NilClass] the first task in the registry.
# File deployment/app/system/types/stack.rb, line 29 def first @registry.first end
Returns the last task in the <@registry> @return [RuneRb::System::Types::Task, NilClass] the last task in the registry.
# File deployment/app/system/types/stack.rb, line 35 def last @registry.last end
Returns the length of the registry @return [Integer]
# File deployment/app/system/types/stack.rb, line 41 def length @registry.length end
Pushes a new task to the Stack. Options are passed directly to the Task
constructor.
The <@registry> object is a SortedSet which automatically organizes each task on submission and links the task's process to its predecessor's (via Task#target_to
). @param task [RuneRb::System::Types::Task] the task to post.
# File deployment/app/system/types/stack.rb, line 15 def push(task) @registry << task end
Sorts the registry and links it's children via Task#target_to
# File deployment/app/system/types/stack.rb, line 46 def sort! @registry.sort! @registry.each do |task| next if task == last task.target_to(@registry[@registry.index(task) + 1].worker) end end