class MockEM::MockEM::ScheduledTasks
Keeps track of tasks to execute in the future, each one consisting of a timestamp and proc to execute.
Constants
- ScheduledTask
Public Class Methods
new(log)
click to toggle source
# File lib/mock_em/mock_em.rb, line 156 def initialize(log) @log = log clear_and_reset end
Public Instance Methods
add_task(timestamp_millis, &block)
click to toggle source
# File lib/mock_em/mock_em.rb, line 161 def add_task(timestamp_millis, &block) @tasks << ScheduledTask.new(timestamp_millis, block) @tasks = @tasks.sort_by(&:timestamp) end
clear_and_reset()
click to toggle source
# File lib/mock_em/mock_em.rb, line 177 def clear_and_reset @tasks = [] end
pop_due_tasks(timestamp)
click to toggle source
# File lib/mock_em/mock_em.rb, line 166 def pop_due_tasks(timestamp) due_tasks = @tasks.take_while {|t| t.timestamp <= timestamp } @tasks = @tasks - due_tasks due_tasks.map(&:proc) end
time_of_next_task()
click to toggle source
# File lib/mock_em/mock_em.rb, line 172 def time_of_next_task task = @tasks.first task && task.timestamp end