class Eldritch::Group

Represents a group of {Task tasks} or {DSL#async async calls/block}. It is used to act upon all the tasks in the group.

Public Class Methods

new() click to toggle source
# File lib/eldritch/group.rb, line 8
def initialize
  @tasks = []
  @mutex = ReentrantMutex.new
  @accept = true
end

Public Instance Methods

<<(task) click to toggle source
# File lib/eldritch/group.rb, line 19
def <<(task)
  @mutex.synchronize do
    if @accept
      @tasks << task
      task.start
    end
  end
end
abort() click to toggle source

Aborts the other async calls/blocks in the group

Warning: This call will directly kill underlying threads. This isn't very safe.

@see Task#abort

# File lib/eldritch/group.rb, line 44
def abort
  @mutex.synchronize do
    @accept = false
    others.each &:abort
  end
end
interrupt() click to toggle source

Interrupts the other async calls/blocks in the group

Interruptions are done using exceptions that can be caught by the async calls/blocks to perform cleanup.

@see Task#interrupt

# File lib/eldritch/group.rb, line 56
def interrupt
  @mutex.synchronize do
    @accept = false
    others.each &:interrupt
  end
end
join_all() click to toggle source
# File lib/eldritch/group.rb, line 35
def join_all
  @tasks.each &:join
end
others() click to toggle source

@return [Array<Task>] the other async calls/blocks in the group

# File lib/eldritch/group.rb, line 15
def others
  @tasks - [Thread.current.eldritch_task]
end
synchronize(&block) click to toggle source

Yields the block in mutual exclusion with all the async calls/tasks

@yield

# File lib/eldritch/group.rb, line 31
def synchronize(&block)
  @mutex.synchronize { block.call }
end