8000 More general handling of IO instance_methods. · socketry/async-io@78b202b · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Aug 29, 2024. It is now read-only.

Commit 78b202b

Browse files
committed
More general handling of IO instance_methods.
1 parent dfcb927 commit 78b202b

File tree

5 files changed

+29
-5
lines changed

5 files changed

+29
-5
lines changed

lib/async/io/generic.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,39 @@ def wrap(*args)
7575
end
7676
end
7777

78-
wraps ::IO, :external_encoding, :internal_encoding, :autoclose?, :autoclose=, :pid, :stat, :binmode, :flush, :set_encoding, :to_io, :to_i, :reopen, :fileno, :fsync, :fdatasync, :sync, :sync=, :tell, :seek, :rewind, :pos, :pos=, :eof, :eof?, :close_on_exec?, :close_on_exec=, :closed?, :close_read, :close_write, :isatty, :tty?, :binmode?, :sysseek, :advise, :ioctl, :fcntl
78+
wraps ::IO, :external_encoding, :internal_encoding, :autoclose?, :autoclose=, :pid, :stat, :binmode, :flush, :set_encoding, :to_io, :to_i, :reopen, :fileno, :fsync, :fdatasync, :sync, :sync=, :tell, :seek, :rewind, :pos, :pos=, :eof, :eof?, :close_on_exec?, :close_on_exec=, :closed?, :close_read, :close_write, :isatty, :tty?, :binmode?, :sysseek, :advise, :ioctl, :fcntl, :nread, :ready?, :pread, :pwrite, :pathconf
7979

8080
# @example
8181
# data = io.read(512)
8282
wrap_blocking_method :read, :read_nonblock
8383
alias sysread read
84+
alias readpartial read
8485

8586
# @example
8687
# io.write("Hello World")
8788
wrap_blocking_method :write, :write_nonblock
8889
alias syswrite write
90+
alias << write
91+
92+
def wait(timeout = nil, mode = :read)
93+
case mode
94+
when :read
95+
wait_readable(timeout)
96+
when :write
97+
wait_writable(timeout)
98+
else
99+
wait_any(:rw, timeout)
100+
end
101+
end
102+
103+
def nonblock
104+
true
105+
end
106+
alias nonblock= nonblock
107+
108+
def nonblock?
109+
true
110+
end
89111

90112
protected
91113

spec/async/io/generic_examples.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
RSpec.shared_examples Async::IO::Generic do |ignore_methods|
33
let(:instance_methods) {described_class.wrapped_klass.instance_methods(false) - (ignore_methods || [])}
4-
let(:wrapped_instance_methods) {described_class.instance_methods(false)}
4+
let(:wrapped_instance_methods) {described_class.instance_methods}
55

66
it "should wrap a class" do
77
expect(described_class.wrapped_klass).to_not be_nil

spec/async/io/generic_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
RSpec.describe Async::IO::Generic do
2626
include_context Async::RSpec::Reactor
2727

28-
# it_should_behave_like Async::IO::Generic
28+
it_should_behave_like Async::IO::Generic, [
29+
:bytes, :chars, :codepoints, :each, :each_byte, :each_char, :each_codepoint, :each_line, :getbyte, :getc, :gets, :lineno, :lineno=, :lines, :print, :printf, :putc, :puts, :readbyte, :readchar, :readline, :readlines, :ungetbyte, :ungetc
30+
]
2931

3032
let(:pipe) {IO.pipe}
3133
let(:input) {Async::IO::Generic.new(pipe.first)}

spec/async/io/socket_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
require_relative 'generic_examples'
2424

2525
RSpec A563 .describe Async::IO::BasicSocket do
26-
it_should_behave_like Async::IO::Generic, [:read_nonblock, :write_nonblock]
26+
it_should_behave_like Async::IO::Generic
2727
end
2828

2929
RSpec.describe Async::IO::Socket do

spec/async/io/ssl_socket_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
include_context Async::RSpec::Reactor
2828
include_context Async::RSpec::SSL::VerifiedContexts
2929

30-
it_should_behave_like Async::IO::Generic, [:sync_close, :to_io, :io]
30+
it_should_behave_like Async::IO::Generic
3131

3232
# Shared port for localhost network tests.
3333
let(:endpoint) {Async::IO::Endpoint.tcp("127.0.0.1", 6779, reuse_port: true)}

0 commit comments

Comments
 (0)
0