Method: Concurrent::TimerSet#post

Defined in:
lib/concurrent/executor/timer_set.rb

#post(delay, *args) { ... } ⇒ Concurrent::ScheduledTask, false

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.

Parameters:

  • delay (Float)

    the number of seconds to wait for before executing the task.

  • args (Array<Object>)

    the arguments passed to the task on execution.

Yields:

  • the task to be performed.

Returns:

Raises:

  • (ArgumentError)

    if the intended execution time is not in the future.

  • (ArgumentError)

    if no block is given.



48
49
50
51
52
53
54
55
56
57
58
# 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