ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:105212] [Ruby master Feature#18162] Shorthand method Proc#isolate to create isolated proc objects
@ 2021-09-13  2:32 tagomoris (Satoshi TAGOMORI)
  2021-09-13  2:33 ` [ruby-core:105213] " tagomoris (Satoshi TAGOMORI)
  0 siblings, 1 reply; 2+ messages in thread
From: tagomoris (Satoshi TAGOMORI) @ 2021-09-13  2:32 UTC (permalink / raw
  To: ruby-core

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/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [ruby-core:105213] [Ruby master Feature#18162] Shorthand method Proc#isolate to create isolated proc objects
  2021-09-13  2:32 [ruby-core:105212] [Ruby master Feature#18162] Shorthand method Proc#isolate to create isolated proc objects tagomoris (Satoshi TAGOMORI)
@ 2021-09-13  2:33 ` tagomoris (Satoshi TAGOMORI)
  0 siblings, 0 replies; 2+ messages in thread
From: tagomoris (Satoshi TAGOMORI) @ 2021-09-13  2:33 UTC (permalink / raw
  To: ruby-core

Issue #18162 has been updated by tagomoris (Satoshi TAGOMORI).


The related ticket is here about Proc#isolated? https://bugs.ruby-lang.org/issues/18137

----------------------------------------
Feature #18162: Shorthand method Proc#isolate to create isolated proc objects
https://bugs.ruby-lang.org/issues/18162#change-93620

* 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/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-09-13  2:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-13  2:32 [ruby-core:105212] [Ruby master Feature#18162] Shorthand method Proc#isolate to create isolated proc objects tagomoris (Satoshi TAGOMORI)
2021-09-13  2:33 ` [ruby-core:105213] " tagomoris (Satoshi TAGOMORI)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).