File: with_lambda.rb

package info (click to toggle)
ruby-parallel 1.22.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 464 kB
  • sloc: ruby: 1,930; makefile: 4
file content (20 lines) | stat: -rw-r--r-- 428 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# frozen_string_literal: true
require './spec/cases/helper'

$stdout.sync = true
type = :"in_#{ARGV.fetch(0)}"
all = [3, 2, 1]
produce = -> { all.pop || Parallel::Stop }

class Callback
  def self.call(x)
    $stdout.sync = true
    "ITEM-#{x}"
  end
end

if type == :in_ractors
  puts(Parallel.map(produce, type => 2, ractor: [Callback, :call]))
else
  puts(Parallel.map(produce, type => 2) { |(i, _id)| Callback.call i })
end