[#82706] [Ruby trunk Bug#13851] getting "can't modify string; temporarily locked" on non-frozen instances — cardoso_tiago@...
Issue #13851 has been updated by chucke (Tiago Cardoso).
3 messages
2017/09/07
[#82853] [Ruby trunk Bug#13916] Race condition when sending a signal to a new fork — russell.davis@...
Issue #13916 has been reported by russelldavis (Russell Davis).
3 messages
2017/09/19
[#82892] [Ruby trunk Bug#13921] buffered read_nonblock doesn't work as expected using SSLSocket — cardoso_tiago@...
Issue #13921 has been updated by chucke (Tiago Cardoso).
3 messages
2017/09/20
[ruby-core:82895] [Ruby trunk Feature#13923] Idiom to release resources safely, with less indentations
From:
eregontp@...
Date:
2017-09-20 11:01:28 UTC
List:
ruby-core #82895
Issue #13923 has been updated by Eregon (Benoit Daloze).
tagomoris (Satoshi TAGOMORI) wrote:
> With this code, storage will not be closed if `buffer.close` raises exceptions.
IMHO if buffer.close raises an exception then that should be fixed and not silently ignored.
(e.g. if close fails it could mean the contents is not properly flushed and might be very hard to debug).
A more common way to write code using resources in Ruby is to use blocks:
File.open("foo") do |file|
file.read
end
----------------------------------------
Feature #13923: Idiom to release resources safely, with less indentations
https://bugs.ruby-lang.org/issues/13923#change-66794
* Author: tagomoris (Satoshi TAGOMORI)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
In programs which grabs and releases resources very often, we need to write so much begin-ensure clauses.
```ruby
begin
storage = getStorage()
begin
buffer = storage.get(buffer_id)
# ...
ensure
buffer.close if buffer
end
rescue StorageError => e
# ...
ensure
storage.close if storage
end
```
Such code makes our code fat, and difficult to understand.
I want to write such code like below:
```ruby
# Class of storage and buffer should include a module (like Closeable)
# or be checked with respond_to?(:close)
begin(storage = getStorage(); buffer = storage.get(buffer_id)
# ...
rescue StorageError => e
# ...
end
# (buffer.close if buffer) rescue nil
# (storage.close if storage) rescue nil
```
Other languages also have similar features:
* Java: try-with-resources
* Python: with
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>