Sha256: 1c121f9c8c3e51cc70485a033bed6710ceb207cb6c9f79238f7eb97166f47fc3
Contents?: true
Size: 1.8 KB
Versions: 2
Compression:
Stored size: 1.8 KB
Contents
# frozen_string_literal: true # Released under the MIT License. # Copyright, 2017-2024, by Samuel Williams. # Copyright, 2017, by Kent Gruber. warn "Async::Wrapper is deprecated and will be removed on 2025-03-31. Please use native interfaces instead.", uplevel: 1, category: :deprecated module Async # Represents an asynchronous IO within a reactor. # @deprecated With no replacement. Prefer native interfaces. class Wrapper # An exception that occurs when the asynchronous operation was cancelled. class Cancelled < StandardError end # @parameter io the native object to wrap. # @parameter reactor [Reactor] the reactor that is managing this wrapper, or not specified, it's looked up by way of {Task.current}. def initialize(io, reactor = nil) @io = io @reactor = reactor @timeout = nil end attr_accessor :reactor # Dup the underlying IO. def dup self.class.new(@io.dup) end # The underlying native `io`. attr :io # Wait for the io to become readable. def wait_readable(timeout = @timeout) @io.to_io.wait_readable(timeout) or raise TimeoutError end # Wait for the io to become writable. def wait_priority(timeout = @timeout) @io.to_io.wait_priority(timeout) or raise TimeoutError end # Wait for the io to become writable. def wait_writable(timeout = @timeout) @io.to_io.wait_writable(timeout) or raise TimeoutError end # Wait fo the io to become either readable or writable. # @parameter duration [Float] timeout after the given duration if not `nil`. def wait_any(timeout = @timeout) @io.to_io.wait(::IO::READABLE|::IO::WRITABLE|::IO::PRIORITY, timeout) or raise TimeoutError end # Close the underlying IO. def close @io.close end # Whether the underlying IO is closed. def closed? @io.closed? end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
async-2.21.0 | lib/async/wrapper.rb |
async-2.20.0 | lib/async/wrapper.rb |