[#105450] [Ruby master Feature#18228] Add a `timeout` option to `IO.copy_stream` — "byroot (Jean Boussier)" <noreply@...>
Issue #18228 has been reported by byroot (Jean Boussier).
11 messages
2021/09/27
[ruby-core:105212] [Ruby master Feature#18162] Shorthand method Proc#isolate to create isolated proc objects
From:
"tagomoris (Satoshi TAGOMORI)" <noreply@...>
Date:
2021-09-13 02:32:41 UTC
List:
ruby-core #105212
Issue #18162 has been reported by tagomoris (Satoshi TAGOMORI).
----------------------------------------
Feature #18162: Shorthand method Proc#isolate to create isolated proc objects
https://bugs.ruby-lang.org/issues/18162
* Author: tagomoris (Satoshi TAGOMORI)
* Status: Open
* Priority: Normal
----------------------------------------
Currently, isolated proc objects can be created only via Ractor.make_shareable() method.
But isolated proc objects are useful for other use-cases too. So I want to propose a new method Proc#isolate to make it isolated.
For example, it's useful with async I/O patterns like this:
```ruby
x = 1
y = 2
chk1 = ->(async_io){ async_io.write JSON.dump({x:, y:}) }.isolate
async_make_checkpoint(&chk1)
x = processing_may_fail(x)
y = processing_may_fail(y)
chk2 = ->(async_io){ async_io.write JSON.dump({x:, y:}) }.isolate
async_make_checkpoint(&chk2)
# ...
```
In the use-case above, async_make_checkpoint is to create a checkpoint in an async manner to record the (lexical) "current" value of variables. If we can do the thing like above, we'll be able to record how values of x/y are changed (or not changed).
In my opinion, we'll have many similar use-cases because Ruby 3.x has the fiber scheduler.
And of course, this should be also useful to define shareable methods using Module#define_method.
```ruby
x = 1
define_method(:get_x, &->(){ x }.isolate)
# is much simpler than below
x = 1
getter_x = Ractor.make_shareable(->(){ x })
define_method(:get_x, &getter_x)
```
--
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>