Sha256: 90cf1bc5af3a27c0d247bdbeb992d701fcdac3446f7ce06505d6eaeeed9bc1d6
Contents?: true
Size: 851 Bytes
Versions: 3
Compression:
Stored size: 851 Bytes
Contents
# frozen_string_literal: true class Fiber module Collector class All def initialize(procs) @tasks = procs.map { Task.new(_1) } end def wait(timeout) raise "must run on non-blocking fiber" if Fiber.current.blocking? @tasks.each do |task| Fiber.schedule { task.run } end if timeout.nil? sleep 0.001 until @tasks.all?(&:done?) else elapsed = 0 until @tasks.all?(&:done?) task = @tasks.find { |t| t.error } unless task.nil? raise task.error end t = 0.001 sleep t elapsed += t raise "timeout" if elapsed > timeout end end @tasks.map { |t| t.error && raise(t.error) || t.result } end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
fiber-collector-1.0.0 | lib/fiber/collector/builder/all.rb |
fiber-collector-0.1.1 | lib/fiber/collector/builder/all.rb |
fiber-collector-0.1.0 | lib/fiber/collector/builder/all.rb |