lib/polyphony/extensions/fiber.rb
# Waits for at least one of the given fibers to terminate, returning an
# array containing the first terminated fiber and its return value. If an
# exception occurs in one of the given fibers, it will be reraised.
#
# @param *fibers [Array<Fiber>] Fibers to wait for
# @return [Array] Array containing the first terminated fiber and its return value
Waits for at least one of the given fibers to terminate, returning an
array containing the first terminated fiber and its return value. If an
exception occurs in one of the given fibers, it will be reraised.
Waits for at least one of the given fibers to terminate returning an array containing the first terminated fiber and its return value . If an exception occurs in one of the given fibers it will be reraised .
def select(*fibers)
      return nil if fibers.empty?
      current_fiber = self.current
      mailbox = current_fiber.monitor_mailbox
      fibers.each do |f|
        if f.dead?
          result = f.result
          result.is_a?(Exception) ? (raise result) : (return [f, result])
        end
      end
      fibers.each { |f| f.monitor(current_fiber) }
      while true
        (fiber, result) = mailbox.shift
        next unless fibers.include?(fiber)
        fibers.each { |f| f.unmonitor(current_fiber) }
        if result.is_a?(Exception)
          raise result
        else
          return [fiber, result]
        end
      end
    end
def select ( * fibers ) return nil if fibers . empty? current_fiber = self . current mailbox = current_fiber . monitor_mailbox fibers . each do | f | if f . dead? result = f . result result . is_a? ( Exception ) ? ( raise result ) : ( return [ f , result ] ) end end fibers . each { | f | f . monitor ( current_fiber ) } while true ( fiber , result ) = mailbox . shift next unless fibers . include? ( fiber ) fibers . each { | f | f . unmonitor ( current_fiber ) } if result . is_a? ( Exception ) raise result else return [ fiber , result ] end end end
Waits for at least one of the given fibers to terminate, returning an
array containing the first terminated fiber and its return value.
Waits for at least one of the given fibers to terminate returning an array containing the first terminated fiber and its return value .
Array containing the first terminated fiber and its return value
Array containing the first terminated fiber and its return value
Array
fibers
<not_specific>
*fibers
<not_specific>
Fibers to wait for
Fibers to wait for