A little cleanup
1 files changed, 6 insertions(+), 11 deletions(-) M src/map_parallel.cr
M src/map_parallel.cr => src/map_parallel.cr +6 -11
@@ 1,15 1,10 @@ module Enumerable(T) def map_parallel(&block : T -> U) forall U wait = Channel(U).new num_fibers = 0 self .tap { |x| num_fibers = x.size } .each do |x| spawn do wait.send(block.call(x)) end end Array.new(num_fibers, nil) .map { |x| wait.receive } output_ch = Channel(U).new self.each do |x| spawn { output_ch.send(block.call(x)) } end Array.new(self.size, nil) .map { |x| output_ch.receive } end end