async-io 1.9.4 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7bbfa95265fdfbad86f84c9dde06206b8bbff48a5e8a0babc4954e89f18eb39
4
- data.tar.gz: 897713b11214878f3ba9cf782830ee9eacc0d2e8fbc992e7e0b76fbe6704bf7c
3
+ metadata.gz: c16b3fc4731d433938fa0e1e17dfc6f9adf6d04e5be969490d48393c0c1e88c8
4
+ data.tar.gz: ce83e964e7bac569a90fc6c53130b0fbfe6ef8f331ecd8e070711237dc36e170
5
5
  SHA512:
6
- metadata.gz: f397bef79346d21743874a4d9e3385447f9c0469ae49e68809ff196611c8edfaddfbe5f4b82d0b7afe745706d5a72fbcc7f5eb293333321530683b3385eac4ee
7
- data.tar.gz: 35425a42630fb19264e4840307204bd0d24ec63079fa1ac599e59669127075ce2cdece2d05fd3ba5b534f12100f6514449857e352cb0d0716bbafc0bb759323a
6
+ metadata.gz: c75b738875dab6744261a409eda31b33356fe0350fbf1baa61103294ef5166ba93f70b73428ba41c2077976b69aa6b755c71f8221b74ed913b7a13ad7bb0b7bb
7
+ data.tar.gz: 6e9f04ae63f63698bdfc611e67af677a293f103561de4cfb163de5e92aa3573ac89623d642e25419e5a4abc3436aae4d91d990c294852c6bcbca26ab269c039f
@@ -48,7 +48,7 @@ module Async
48
48
  end
49
49
 
50
50
  def read_line
51
- @stream.read_until(@eol) or raise EOFError
51
+ @stream.read_until(@eol) or @stream.eof!
52
52
  end
53
53
 
54
54
  def peek_line
@@ -138,11 +138,22 @@ module Async
138
138
  flush
139
139
  end
140
140
 
141
+ def closed?
142
+ @io.closed?
143
+ end
144
+
141
145
  # Closes the stream and flushes any unwritten data.
142
146
  def close
143
- flush
144
- ensure
145
- @io.close
147
+ return if @io.closed?
148
+
149
+ begin
150
+ flush
151
+ rescue
152
+ # We really can't do anything here unless we want #close to raise exceptions.
153
+ Async.logger.error(self) {$!}
154
+ ensure
155
+ @io.close
156
+ end
146
157
  end
147
158
 
148
159
  # Returns true if the stream is at file which means there is no more data to be read.
@@ -154,6 +165,13 @@ module Async
154
165
 
155
166
  alias eof eof?
156
167
 
168
+ def eof!
169
+ @read_buffer.clear
170
+ @eof = true
171
+
172
+ raise EOFError
173
+ end
174
+
157
175
  private
158
176
 
159
177
  # Fills the buffer from the underlying stream.
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Async
22
22
  module IO
23
- VERSION = "1.9.4"
23
+ VERSION = "1.10.0"
24
24
  end
25
25
  end
@@ -97,4 +97,29 @@ RSpec.describe Async::IO::Stream do
97
97
  expect(io.string).to be == "Hello World\n"
98
98
  end
99
99
  end
100
+
101
+ describe '#eof' do
102
+ it "should terminate stream" do
103
+ expect do
104
+ stream.eof!
105
+ end.to raise_error(EOFError)
106
+
107
+ expect(stream).to be_eof
108
+ end
109
+ end
110
+
111
+ describe '#close' do
112
+ it 'can be closed even if underlying io is closed' do
113
+ io.close
114
+
115
+ expect(stream.io).to be_closed
116
+
117
+ # Put some data in the write buffer
118
+ stream.write "."
119
+
120
+ expect do
121
+ stream.close
122
+ end.to_not raise_error
123
+ end
124
+ end
100
125
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-io
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.4
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-30 00:00:00.000000000 Z
11
+ date: 2018-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async