Methods

Files

Class/Module Index [+]

Quicksearch

Concurrent::TimerSet

Executes a collection of tasks, each after a given delay. A master task monitors the set and schedules each task for execution at the appropriate time. Tasks are run on the global thread pool or on the supplied executor. Each task is represented as a `ScheduledTask`.

@see Concurrent::ScheduledTask

@!macro monotonic_clock_warning

Public Class Methods

new(opts = {}) click to toggle source

Create a new set of timed tasks.

@!macro [attach] executor_options

@param [Hash] opts the options used to specify the executor on which to perform actions
@option opts [Executor] :executor when set use the given `Executor` instance.
  Three special values are also supported: `:task` returns the global task pool,
  `:operation` returns the global operation pool, and `:immediate` returns a new
  `ImmediateExecutor` object.
# File lib/concurrent/executor/timer_set.rb, line 30
def initialize(opts = {})
  super(opts)
end

Public Instance Methods

kill() click to toggle source

Begin an immediate shutdown. In-progress tasks will be allowed to complete but enqueued tasks will be dismissed and no new tasks will be accepted. Has no additional effect if the thread pool is not running.

# File lib/concurrent/executor/timer_set.rb, line 64
def kill
  shutdown
end
post(delay, *args, &task) click to toggle source

Post a task to be execute run after a given delay (in seconds). If the delay is less than 1/100th of a second the task will be immediately post to the executor.

@param [Float] delay the number of seconds to wait for before executing the task. @param [Array<Object>] args the arguments passed to the task on execution.

@yield the task to be performed.

@return [Concurrent::ScheduledTask, false] IVar representing the task if the post

is successful; false after shutdown.

@raise [ArgumentError] if the intended execution time is not in the future. @raise [ArgumentError] if no block is given.

# File lib/concurrent/executor/timer_set.rb, line 48
def post(delay, *args, &task)
  raise ArgumentError.new('no block given') unless block_given?
  return false unless running?
  opts = {
    executor: @task_executor,
    args: args,
    timer_set: self
  }
  task = ScheduledTask.execute(delay, opts, &task) # may raise exception
  task.unscheduled? ? false : task
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.