Sha256: b08aaf258f8282be78c9621a5e89bff17fed9472324df1b1c017babb661a324e

Contents?: true

Size: 541 Bytes

Versions: 7

Compression:

Stored size: 541 Bytes

Contents

require 'fiber'

class RestCore::Future::FutureFiber < RestCore::Future
  def initialize *args
    super
    self.fibers = []
  end

  def wrap
    Fiber.new{ yield }.resume
  end

  def wait
    fibers << Fiber.current
    Fiber.yield until loaded? # it might be resumed by some other futures!
  end

  def resume
    return if fibers.empty?
    current_fibers = fibers.dup
    fibers.clear
    current_fibers.each{ |f|
      next unless f.alive?
      next_tick{ f.resume }
    }
    resume
  end

  protected
  attr_accessor :fibers
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rest-core-2.1.2 lib/rest-core/engine/future/future_fiber.rb
rest-core-2.1.1 lib/rest-core/engine/future/future_fiber.rb
rest-core-2.1.0 lib/rest-core/engine/future/future_fiber.rb
rest-core-2.0.4 lib/rest-core/engine/future/future_fiber.rb
rest-core-2.0.3 lib/rest-core/engine/future/future_fiber.rb
rest-core-2.0.2 lib/rest-core/engine/future/future_fiber.rb
rest-core-2.0.1 lib/rest-core/engine/future/future_fiber.rb