Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions manual/api/_builtin/IO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2431,6 +2431,46 @@ p IO.new(IO.sysopen("/")).path # => "/"
p IO.new(IO.sysopen("/"), path: "foo").path # => "foo"
```

### def timeout -> Numeric | nil

self に設定されている入出力のタイムアウトを返します。
設定されていない場合は nil を返します。

タイムアウトの設定については [m:IO#timeout=] を参照してください。

```ruby title="例"
r, w = IO.pipe
p r.timeout # => nil
r.timeout = 0.5
p r.timeout # => 0.5
```

- **SEE** [m:IO#timeout=]

### def timeout=(numeric) -> Numeric
### def timeout=(nil) -> nil

self に入出力のタイムアウトを秒単位で設定します。

設定すると、可能な限りすべてのブロッキング操作にこのタイムアウトが適用されます。
操作が設定した時間を超えると [c:IO::TimeoutError] が発生します。

影響を受けるのは [m:IO#gets]、[m:IO#puts]、[m:IO#read]、[m:IO#write]、
[m:IO#wait_readable]、[m:IO#wait_writable] などです
([c:Socket] のブロッキング操作にも影響します)。

- **param** `numeric` -- タイムアウトの秒数を数値で指定します。
nil を指定するとタイムアウトを解除します。

```ruby title="例"
r, w = IO.pipe
r.timeout = 0.1

r.read # ~> IO::TimeoutError
```

- **SEE** [m:IO#timeout], [c:IO::TimeoutError]

#@end

## Constants
Expand Down
16 changes: 16 additions & 0 deletions manual/api/_builtin/IO__TimeoutError.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
library: _builtin
since: "3.2"
---
# class IO::TimeoutError < IOError

入出力の操作が [m:IO#timeout=] で設定した時間を超えたときに発生します。

```ruby
r, w = IO.pipe
r.timeout = 0.1

r.read # ~> IO::TimeoutError
```

- **SEE** [m:IO#timeout=], [m:IO#timeout]
23 changes: 23 additions & 0 deletions manual/api/io/wait.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,26 @@ timeout を指定した場合は、指定秒数経過するまでブロックし
- **param** `timeout` -- タイムアウトまでの秒数を指定します。

- **SEE** [m:IO#wait_readable]

#@since 3.0
### def wait_priority(timeout = nil) -> bool | self | nil

self が優先データを受信して読み込み可能になるまでブロックし、
読み込み可能になったら真値を返します。

優先データ(緊急データ)は [m:Socket::Constants::MSG_OOB] フラグを用いて
送受信され、通常はストリーム型のソケットに限られます。

より詳しくは、一度ブロックしてから読み込み可能になった場合には
self を返します。
内部のバッファにデータがある場合には
ブロックせずに true を返します。

timeout を指定した場合は、指定秒数経過するまでブロックし、タ
イムアウトした場合は nil を返します。

- **param** `timeout` -- タイムアウトまでの秒数を指定します。
nil を指定すると読み込み可能になるまで待ち続けます。

- **SEE** [m:IO#wait_readable], [m:IO#wait_writable]
#@end