Method: AsyncCable::Util.create_task

Defined in:
lib/async_cable/util.rb

.create_task(parent = Async::Task.current?, schedule = false, &block) ⇒ Async::Task

Return created task.

Parameters:

  • parent (Async::Task, NilClass) (defaults to: Async::Task.current?)

    parent task for new one.

  • schedule (Boolean) (defaults to: false)

    run now if true, otherwise will be run at next reactor loop cycle.

Returns:

  • (Async::Task)

    return created task.



6
7
8
9
10
11
12
13
14
# File 'lib/async_cable/util.rb', line 6

def create_task(parent = Async::Task.current?, schedule = false, &block)
  task = Async::Task.new(parent, &block)
  if schedule
    Async::Task.current.reactor << task.fiber
  else
    task.run
  end
  task
end