Class: Zapp::Pipe

Inherits:
Ractor
  • Object
show all
Defined in:
lib/zapp/pipe.rb

Overview

Light wrapper around a Ractor for piping messages CSP style

Class Method Summary collapse

Class Method Details

.for(*klasses, null: true) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/zapp/pipe.rb', line 6

def self.for(*klasses, null: true)
  Ractor.new(klasses, null) do |klasses, null|
    loop do
      Ractor.yield(
        Ractor.receive_if do |msg|
          return true if null && msg.nil?

          klasses.any? { |klass| msg.is_a?(klass) }
        end
      )
    end
  end
end

.newObject



20
21
22
23
24
25
26
# File 'lib/zapp/pipe.rb', line 20

def self.new
  super do
    loop do
      Ractor.yield(Ractor.receive)
    end
  end
end