Sha256: 86f5f7f655ded829064006e75668fcd84d4d33775b798bd848a02086ec3c9344
Contents?: true
Size: 747 Bytes
Versions: 3
Compression:
Stored size: 747 Bytes
Contents
# frozen_string_literal: true module Spandx module Core class Concurrent include Enumerable def self.map(items, pool:, &block) queue = Queue.new items.each do |item| pool.schedule([item, block]) do |marshalled_item, callable| queue.enq(callable.call(marshalled_item)) end end new(queue, items.size) end attr_reader :queue, :size def initialize(queue, size) @queue = queue @size = size end def each size.times { yield queue.deq } end def to_enum Enumerator.new do |yielder| each do |item| yielder.yield item end end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
spandx-0.13.2 | lib/spandx/core/concurrent.rb |
spandx-0.13.1 | lib/spandx/core/concurrent.rb |
spandx-0.13.0 | lib/spandx/core/concurrent.rb |