lib/zapp/pipe.rb in zapp-0.2.5 vs lib/zapp/pipe.rb in zapp-0.2.6

- old
+ new

@@ -1,9 +1,23 @@ # frozen_string_literal: true module Zapp # Light wrapper around a Ractor for piping messages CSP style class Pipe < Ractor + 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 + def self.new super do loop do Ractor.yield(Ractor.receive) end