Sha256: 7ef659a35e4b7272fb638fed76275ba86a4fd2f30aaa185008b8303b551b74cd

Contents?: true

Size: 750 Bytes

Versions: 12

Compression:

Stored size: 750 Bytes

Contents

# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2022-2023, by Samuel Williams.

require_relative 'endpoint'

module Async
	module IO
		class CompositeEndpoint < Endpoint
			def initialize(endpoints, **options)
				super(**options)
				@endpoints = endpoints
			end
			
			def each(&block)
				@endpoints.each(&block)
			end
			
			def connect(&block)
				error = nil
				
				@endpoints.each do |endpoint|
					begin
						return endpoint.connect(&block)
					rescue => error
					end
				end
				
				raise error
			end
			
			def bind(&block)
				@endpoints.map(&:bind)
			end
		end
		
		class Endpoint
			def self.composite(*endpoints, **options)
				CompositeEndpoint.new(endpoints, **options)
			end
		end
	end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
async-io-1.43.2 lib/async/io/composite_endpoint.rb
async-io-1.43.1 lib/async/io/composite_endpoint.rb
async-io-1.43.0 lib/async/io/composite_endpoint.rb
async-io-1.42.1 lib/async/io/composite_endpoint.rb
async-io-1.42.0 lib/async/io/composite_endpoint.rb
async-io-1.41.0 lib/async/io/composite_endpoint.rb
async-io-1.39.0 lib/async/io/composite_endpoint.rb
async-io-1.38.1 lib/async/io/composite_endpoint.rb
async-io-1.38.0 lib/async/io/composite_endpoint.rb
async-io-1.37.0 lib/async/io/composite_endpoint.rb
async-io-1.36.1 lib/async/io/composite_endpoint.rb
async-io-1.36.0 lib/async/io/composite_endpoint.rb