module AsyncCable::Util
Public Class Methods
create_task(parent = Async::Task.current?, schedule = false, &block)
click to toggle source
@param parent [Async::Task,NilClass] parent task for new one. @param schedule [Boolean] run now if true, otherwise will be run at next reactor loop cycle. @return [Async::Task] return created task.
# 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
each_async(list, *args) { |item| ... }
click to toggle source
Each yield will be executed within it's own fiber. @param list [Array] list that will be iterable. @param args [Array] parent, schedule @see create_task
(optional).
# File lib/async_cable/util.rb, line 19 def each_async(list, *args) list.each do |item| create_task(*args) { yield item } end end
Private Instance Methods
create_task(parent = Async::Task.current?, schedule = false, &block)
click to toggle source
@param parent [Async::Task,NilClass] parent task for new one. @param schedule [Boolean] run now if true, otherwise will be run at next reactor loop cycle. @return [Async::Task] return created task.
# 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
each_async(list, *args) { |item| ... }
click to toggle source
Each yield will be executed within it's own fiber. @param list [Array] list that will be iterable. @param args [Array] parent, schedule @see create_task
(optional).
# File lib/async_cable/util.rb, line 19 def each_async(list, *args) list.each do |item| create_task(*args) { yield item } end end