ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:65537] [ruby-trunk - Feature #10344] [Open] [PATCH] Implement Fiber#raise
       [not found] <redmine.issue-10344.20141009002911@ruby-lang.org>
@ 2014-10-09  0:29 ` Knut.Franke
  2014-10-09  2:58 ` [ruby-core:65540] [ruby-trunk - Feature #10344] " ko1
                   ` (19 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: Knut.Franke @ 2014-10-09  0:29 UTC (permalink / raw
  To: ruby-core

Issue #10344 has been reported by Knut Franke.

----------------------------------------
Feature #10344: [PATCH] Implement Fiber#raise
https://bugs.ruby-lang.org/issues/10344

* Author: Knut Franke
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
While it is possible to implement this in pure Ruby (by wrapping Fiber.yield and Fiber#resume), this feels like a low-level feature that ought to be provided out of the box. Also, the C implementation is more straight-forward, and more efficient. Unfortunately, it is not quite possible to implement this as a C extension module (without resorting to wrappers again); cf. the change to make_passing_arg().

Example usage:

~~~
fib = Fiber.new do
  counter = 0
  loop { counter += Fiber.yield }
  counter
end
fib.resume
fib.resume 10
fib.resume 100
fib.raise StopIteration # => 110
~~~

---Files--------------------------------
0001-Implement-Fiber-raise.patch (4.12 KB)


-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:65540] [ruby-trunk - Feature #10344] [PATCH] Implement Fiber#raise
       [not found] <redmine.issue-10344.20141009002911@ruby-lang.org>
  2014-10-09  0:29 ` [ruby-core:65537] [ruby-trunk - Feature #10344] [Open] [PATCH] Implement Fiber#raise Knut.Franke
@ 2014-10-09  2:58 ` ko1
  2014-10-09 10:16 ` [ruby-core:65558] " funny.falcon
                   ` (18 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: ko1 @ 2014-10-09  2:58 UTC (permalink / raw
  To: ruby-core

Issue #10344 has been updated by Koichi Sasada.


Do you have good example to use it?


----------------------------------------
Feature #10344: [PATCH] Implement Fiber#raise
https://bugs.ruby-lang.org/issues/10344#change-49309

* Author: Knut Franke
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
While it is possible to implement this in pure Ruby (by wrapping Fiber.yield and Fiber#resume), this feels like a low-level feature that ought to be provided out of the box. Also, the C implementation is more straight-forward, and more efficient. Unfortunately, it is not quite possible to implement this as a C extension module (without resorting to wrappers again); cf. the change to make_passing_arg().

Example usage:

~~~
fib = Fiber.new do
  counter = 0
  loop { counter += Fiber.yield }
  counter
end
fib.resume
fib.resume 10
fib.resume 100
fib.raise StopIteration # => 110
~~~

---Files--------------------------------
0001-Implement-Fiber-raise.patch (4.12 KB)


-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:65558] [ruby-trunk - Feature #10344] [PATCH] Implement Fiber#raise
       [not found] <redmine.issue-10344.20141009002911@ruby-lang.org>
  2014-10-09  0:29 ` [ruby-core:65537] [ruby-trunk - Feature #10344] [Open] [PATCH] Implement Fiber#raise Knut.Franke
  2014-10-09  2:58 ` [ruby-core:65540] [ruby-trunk - Feature #10344] " ko1
@ 2014-10-09 10:16 ` funny.falcon
  2014-10-11 16:28 ` [ruby-core:65618] " Knut.Franke
                   ` (17 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: funny.falcon @ 2014-10-09 10:16 UTC (permalink / raw
  To: ruby-core

Issue #10344 has been updated by Yura Sokolov.


Yes: it is missing piece to make "greenlet" port, in other words - green threads that mimics real threads.
To accomplish that there is a need to raise exception in a fiber waiting on event if event fails.
As Knut said it could be implemented in a Ruby, but it feels to be dirty way. If implemented in C it will lead to cleaner implementation.


----------------------------------------
Feature #10344: [PATCH] Implement Fiber#raise
https://bugs.ruby-lang.org/issues/10344#change-49318

* Author: Knut Franke
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
While it is possible to implement this in pure Ruby (by wrapping Fiber.yield and Fiber#resume), this feels like a low-level feature that ought to be provided out of the box. Also, the C implementation is more straight-forward, and more efficient. Unfortunately, it is not quite possible to implement this as a C extension module (without resorting to wrappers again); cf. the change to make_passing_arg().

Example usage:

~~~
fib = Fiber.new do
  counter = 0
  loop { counter += Fiber.yield }
  counter
end
fib.resume
fib.resume 10
fib.resume 100
fib.raise StopIteration # => 110
~~~

---Files--------------------------------
0001-Implement-Fiber-raise.patch (4.12 KB)


-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:65618] [ruby-trunk - Feature #10344] [PATCH] Implement Fiber#raise
       [not found] <redmine.issue-10344.20141009002911@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2014-10-09 10:16 ` [ruby-core:65558] " funny.falcon
@ 2014-10-11 16:28 ` Knut.Franke
  2014-10-16  4:36   ` [ruby-core:65747] " SASADA Koichi
  2014-10-16  4:41 ` [ruby-core:65748] " ko1
                   ` (16 subsequent siblings)
  20 siblings, 1 reply; 23+ messages in thread
From: Knut.Franke @ 2014-10-11 16:28 UTC (permalink / raw
  To: ruby-core

Issue #10344 has been updated by Knut Franke.


For some more sophisticated examples, see https://github.com/nome/coroutines. The library does work with vanilla Ruby, but the patch improves performance.

Also, similar code can be simplified by using Fiber#raise. Compare e.g. the two implementation of Consumer::Yielder#await at
https://github.com/nome/coroutines/blob/master/lib/coroutines/base.rb

----------------------------------------
Feature #10344: [PATCH] Implement Fiber#raise
https://bugs.ruby-lang.org/issues/10344#change-49355

* Author: Knut Franke
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
While it is possible to implement this in pure Ruby (by wrapping Fiber.yield and Fiber#resume), this feels like a low-level feature that ought to be provided out of the box. Also, the C implementation is more straight-forward, and more efficient. Unfortunately, it is not quite possible to implement this as a C extension module (without resorting to wrappers again); cf. the change to make_passing_arg().

Example usage:

~~~
fib = Fiber.new do
  counter = 0
  loop { counter += Fiber.yield }
  counter
end
fib.resume
fib.resume 10
fib.resume 100
fib.raise StopIteration # => 110
~~~

---Files--------------------------------
0001-Implement-Fiber-raise.patch (4.12 KB)


-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:65747] Re: [ruby-trunk - Feature #10344] [PATCH] Implement Fiber#raise
  2014-10-11 16:28 ` [ruby-core:65618] " Knut.Franke
@ 2014-10-16  4:36   ` SASADA Koichi
  0 siblings, 0 replies; 23+ messages in thread
From: SASADA Koichi @ 2014-10-16  4:36 UTC (permalink / raw
  To: ruby-core

On 2014/10/12 1:28, Knut.Franke@gmx.de wrote:
> For some more sophisticated examples, see https://github.com/nome/coroutines. The library does work with vanilla Ruby, but the patch improves performance.
> 
> Also, similar code can be simplified by using Fiber#raise. Compare e.g. the two implementation of Consumer::Yielder#await at
> https://github.com/nome/coroutines/blob/master/lib/coroutines/base.rb

I understand this feature helps some libraries. But I can't understand
why it is important.

I'm afraid that introducing such feature increases complexity of Fiber.
Basically, I want to recommend strongly that using Fiber as
semi-croutine, ristricted feature.

At least, such feature should be located at ext/fiber.

-- 
// SASADA Koichi at atdot dot net

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

* [ruby-core:65748] [ruby-trunk - Feature #10344] [PATCH] Implement Fiber#raise
       [not found] <redmine.issue-10344.20141009002911@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2014-10-11 16:28 ` [ruby-core:65618] " Knut.Franke
@ 2014-10-16  4:41 ` ko1
  2014-10-18 11:59   ` [ruby-core:65780] " Юрий Соколов
  2014-10-18 12:11 ` [ruby-core:65781] " funny.falcon
                   ` (15 subsequent siblings)
  20 siblings, 1 reply; 23+ messages in thread
From: ko1 @ 2014-10-16  4:41 UTC (permalink / raw
  To: ruby-core

Issue #10344 has been updated by Koichi Sasada.


 On 2014/10/12 1:28, Knut.Franke@gmx.de wrote:
 > For some more sophisticated examples, see https://github.com/nome/coroutines. The library does work with vanilla Ruby, but the patch improves performance.
 > 
 > Also, similar code can be simplified by using Fiber#raise. Compare e.g. the two implementation of Consumer::Yielder#await at
 > https://github.com/nome/coroutines/blob/master/lib/coroutines/base.rb
 
 I understand this feature helps some libraries. But I can't understand
 why it is important.
 
 I'm afraid that introducing such feature increases complexity of Fiber.
 Basically, I want to recommend strongly that using Fiber as
 semi-croutine, ristricted feature.
 
 At least, such feature should be located at ext/fiber.
 
 -- 
 // SASADA Koichi at atdot dot net

----------------------------------------
Feature #10344: [PATCH] Implement Fiber#raise
https://bugs.ruby-lang.org/issues/10344#change-49483

* Author: Knut Franke
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
While it is possible to implement this in pure Ruby (by wrapping Fiber.yield and Fiber#resume), this feels like a low-level feature that ought to be provided out of the box. Also, the C implementation is more straight-forward, and more efficient. Unfortunately, it is not quite possible to implement this as a C extension module (without resorting to wrappers again); cf. the change to make_passing_arg().

Example usage:

~~~
fib = Fiber.new do
  counter = 0
  loop { counter += Fiber.yield }
  counter
end
fib.resume
fib.resume 10
fib.resume 100
fib.raise StopIteration # => 110
~~~

---Files--------------------------------
0001-Implement-Fiber-raise.patch (4.12 KB)


-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:65780] Re: [ruby-trunk - Feature #10344] [PATCH] Implement Fiber#raise
  2014-10-16  4:41 ` [ruby-core:65748] " ko1
@ 2014-10-18 11:59   ` Юрий Соколов
  0 siblings, 0 replies; 23+ messages in thread
From: Юрий Соколов @ 2014-10-18 11:59 UTC (permalink / raw
  To: Ruby developers

[-- Attachment #1: Type: text/plain, Size: 2452 bytes --]

> At least, such feature should be located at ext/fiber.

even if ext/fiber it is still should be implemented in C .

> I'm afraid that introducing such feature increases complexity of Fiber.

Not too much. Look at the patch: it uses same hook as rb_fiber_terminate.

By the way, why Thread has this feature?
http://www.ruby-doc.org/core-2.1.3/Thread.html#method-i-raise
And why Fiber hasn't? In fact, it is strange that this feature still not
presented, cause it is expected to exists.


2014-10-16 8:41 GMT+04:00 <ko1@atdot.net>:

> Issue #10344 has been updated by Koichi Sasada.
>
>
>  On 2014/10/12 1:28, Knut.Franke@gmx.de wrote:
>  > For some more sophisticated examples, see
> https://github.com/nome/coroutines. The library does work with vanilla
> Ruby, but the patch improves performance.
>  >
>  > Also, similar code can be simplified by using Fiber#raise. Compare e.g.
> the two implementation of Consumer::Yielder#await at
>  > https://github.com/nome/coroutines/blob/master/lib/coroutines/base.rb
>
>  I understand this feature helps some libraries. But I can't understand
>  why it is important.
>
>  I'm afraid that introducing such feature increases complexity of Fiber.
>  Basically, I want to recommend strongly that using Fiber as
>  semi-croutine, ristricted feature.
>
>  At least, such feature should be located at ext/fiber.
>
>  --
>  // SASADA Koichi at atdot dot net
>
> ----------------------------------------
> Feature #10344: [PATCH] Implement Fiber#raise
> https://bugs.ruby-lang.org/issues/10344#change-49483
>
> * Author: Knut Franke
> * Status: Open
> * Priority: Normal
> * Assignee:
> * Category:
> * Target version:
> ----------------------------------------
> While it is possible to implement this in pure Ruby (by wrapping
> Fiber.yield and Fiber#resume), this feels like a low-level feature that
> ought to be provided out of the box. Also, the C implementation is more
> straight-forward, and more efficient. Unfortunately, it is not quite
> possible to implement this as a C extension module (without resorting to
> wrappers again); cf. the change to make_passing_arg().
>
> Example usage:
>
> ~~~
> fib = Fiber.new do
>   counter = 0
>   loop { counter += Fiber.yield }
>   counter
> end
> fib.resume
> fib.resume 10
> fib.resume 100
> fib.raise StopIteration # => 110
> ~~~
>
> ---Files--------------------------------
> 0001-Implement-Fiber-raise.patch (4.12 KB)
>
>
> --
> https://bugs.ruby-lang.org/
>

[-- Attachment #2: Type: text/html, Size: 3578 bytes --]

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

* [ruby-core:65781] [ruby-trunk - Feature #10344] [PATCH] Implement Fiber#raise
       [not found] <redmine.issue-10344.20141009002911@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2014-10-16  4:41 ` [ruby-core:65748] " ko1
@ 2014-10-18 12:11 ` funny.falcon
  2014-10-18 13:55 ` [ruby-core:65782] " Knut.Franke
                   ` (14 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: funny.falcon @ 2014-10-18 12:11 UTC (permalink / raw
  To: ruby-core

Issue #10344 has been updated by Yura Sokolov.


 > At least, such feature should be located at ext/fiber.
 
 even if ext/fiber it is still should be implemented in C .
 
 > I'm afraid that introducing such feature increases complexity of Fiber.
 
 Not too much. Look at the patch: it uses same hook as rb_fiber_terminate.
 
 By the way, why Thread has this feature?
 http://www.ruby-doc.org/core-2.1.3/Thread.html#method-i-raise
 And why Fiber hasn't? In fact, it is strange that this feature still not
 presented, cause it is expected to exists.
 
 
 2014-10-16 8:41 GMT+04:00 <ko1@atdot.net>:
 
 > Issue #10344 has been updated by Koichi Sasada.
 >
 >
 >  On 2014/10/12 1:28, Knut.Franke@gmx.de wrote:
 >  > For some more sophisticated examples, see
 > https://github.com/nome/coroutines. The library does work with vanilla
 > Ruby, but the patch improves performance.
 >  >
 >  > Also, similar code can be simplified by using Fiber#raise. Compare e.g.
 > the two implementation of Consumer::Yielder#await at
 >  > https://github.com/nome/coroutines/blob/master/lib/coroutines/base.rb
 >
 >  I understand this feature helps some libraries. But I can't understand
 >  why it is important.
 >
 >  I'm afraid that introducing such feature increases complexity of Fiber.
 >  Basically, I want to recommend strongly that using Fiber as
 >  semi-croutine, ristricted feature.
 >
 >  At least, such feature should be located at ext/fiber.
 >
 >  --
 >  // SASADA Koichi at atdot dot net
 >
 > ----------------------------------------
 > Feature #10344: [PATCH] Implement Fiber#raise
 > https://bugs.ruby-lang.org/issues/10344#change-49483
 >
 > * Author: Knut Franke
 > * Status: Open
 > * Priority: Normal
 > * Assignee:
 > * Category:
 > * Target version:
 > ----------------------------------------
 > While it is possible to implement this in pure Ruby (by wrapping
 > Fiber.yield and Fiber#resume), this feels like a low-level feature that
 > ought to be provided out of the box. Also, the C implementation is more
 > straight-forward, and more efficient. Unfortunately, it is not quite
 > possible to implement this as a C extension module (without resorting to
 > wrappers again); cf. the change to make_passing_arg().
 >
 > Example usage:
 >
 > ~~~
 > fib = Fiber.new do
 >   counter = 0
 >   loop { counter += Fiber.yield }
 >   counter
 > end
 > fib.resume
 > fib.resume 10
 > fib.resume 100
 > fib.raise StopIteration # => 110
 > ~~~
 >
 > ---Files--------------------------------
 > 0001-Implement-Fiber-raise.patch (4.12 KB)
 >
 >
 > --
 > https://bugs.ruby-lang.org/
 >

----------------------------------------
Feature #10344: [PATCH] Implement Fiber#raise
https://bugs.ruby-lang.org/issues/10344#change-49517

* Author: Knut Franke
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
While it is possible to implement this in pure Ruby (by wrapping Fiber.yield and Fiber#resume), this feels like a low-level feature that ought to be provided out of the box. Also, the C implementation is more straight-forward, and more efficient. Unfortunately, it is not quite possible to implement this as a C extension module (without resorting to wrappers again); cf. the change to make_passing_arg().

Example usage:

~~~
fib = Fiber.new do
  counter = 0
  loop { counter += Fiber.yield }
  counter
end
fib.resume
fib.resume 10
fib.resume 100
fib.raise StopIteration # => 110
~~~

---Files--------------------------------
0001-Implement-Fiber-raise.patch (4.12 KB)


-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:65782] [ruby-trunk - Feature #10344] [PATCH] Implement Fiber#raise
       [not found] <redmine.issue-10344.20141009002911@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2014-10-18 12:11 ` [ruby-core:65781] " funny.falcon
@ 2014-10-18 13:55 ` Knut.Franke
  2014-10-23  1:05 ` [ruby-core:65862] " ko1
                   ` (13 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: Knut.Franke @ 2014-10-18 13:55 UTC (permalink / raw
  To: ruby-core

Issue #10344 has been updated by Knut Franke.

File 0001-Implement-Fiber-raise.patch added
File 0001-Implement-Fiber-raise-in-ext-fiber.patch added

> I understand this feature helps some libraries. But I can't understand why it is important.

Without Fiber#raise, libraries need to use some rather inelegant and inefficient workarounds (wrapping or tagging exceptions, wrapping Fiber.yield etc). Also, having Thread#raise arguably leads one to expect the same functionality in Fiber. I'm not sure whether the feature qualifies as "important", but I still think it is worth including.

> Basically, I want to recommend strongly that using Fiber as semi-croutine, ristricted feature.

I think [Consumer](http://nome.github.io/coroutines/Consumer.html) is an example of a semi-coroutine (in the sense that it uses Fiber.yield, not Fiber#transfer) that benefits from having Fiber#raise.

> At least, such feature should be located at ext/fiber.

I disagree, because the feature is applicable to the restricted (semi-coroutine) fibers available without requiring 'fiber', and indeed implementable on top of them. Nevertheless, I've attached a variant of the patch which adds the method only in ext/fiber (as a compromise solution).

----------------------------------------
Feature #10344: [PATCH] Implement Fiber#raise
https://bugs.ruby-lang.org/issues/10344#change-49518

* Author: Knut Franke
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
While it is possible to implement this in pure Ruby (by wrapping Fiber.yield and Fiber#resume), this feels like a low-level feature that ought to be provided out of the box. Also, the C implementation is more straight-forward, and more efficient. Unfortunately, it is not quite possible to implement this as a C extension module (without resorting to wrappers again); cf. the change to make_passing_arg().

Example usage:

~~~
fib = Fiber.new do
  counter = 0
  loop { counter += Fiber.yield }
  counter
end
fib.resume
fib.resume 10
fib.resume 100
fib.raise StopIteration # => 110
~~~

---Files--------------------------------
0001-Implement-Fiber-raise.patch (4.12 KB)
0001-Implement-Fiber-raise.patch (3.51 KB)
0001-Implement-Fiber-raise-in-ext-fiber.patch (3.6 KB)


-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:65862] [ruby-trunk - Feature #10344] [PATCH] Implement Fiber#raise
       [not found] <redmine.issue-10344.20141009002911@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2014-10-18 13:55 ` [ruby-core:65782] " Knut.Franke
@ 2014-10-23  1:05 ` ko1
  2014-10-23  1:08 ` [ruby-core:65863] " ko1
                   ` (12 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: ko1 @ 2014-10-23  1:05 UTC (permalink / raw
  To: ruby-core

Issue #10344 has been updated by Koichi Sasada.


Yura Sokolov wrote:
> > At least, such feature should be located at ext/fiber.
> 
> even if ext/fiber it is still should be implemented in C .

I agree.

> 
> > I'm afraid that introducing such feature increases complexity of Fiber.
> 
> Not too much. Look at the patch: it uses same hook as `rb_fiber_terminate`.

I don't mention about implementation, but specification.

> By the way, why Thread has this feature?
> http://www.ruby-doc.org/core-2.1.3/Thread.html#method-i-raise
> And why Fiber hasn't? In fact, it is strange that this feature still not
> presented, cause it is expected to exists.

Thread#raise is one of inter communication method (but asynchronouse, difficult, unrecommended way).

Fibers can be under control without such communication.


----------------------------------------
Feature #10344: [PATCH] Implement Fiber#raise
https://bugs.ruby-lang.org/issues/10344#change-49597

* Author: Knut Franke
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
While it is possible to implement this in pure Ruby (by wrapping Fiber.yield and Fiber#resume), this feels like a low-level feature that ought to be provided out of the box. Also, the C implementation is more straight-forward, and more efficient. Unfortunately, it is not quite possible to implement this as a C extension module (without resorting to wrappers again); cf. the change to make_passing_arg().

Example usage:

~~~
fib = Fiber.new do
  counter = 0
  loop { counter += Fiber.yield }
  counter
end
fib.resume
fib.resume 10
fib.resume 100
fib.raise StopIteration # => 110
~~~

---Files--------------------------------
0001-Implement-Fiber-raise.patch (4.12 KB)
0001-Implement-Fiber-raise.patch (3.51 KB)
0001-Implement-Fiber-raise-in-ext-fiber.patch (3.6 KB)


-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:65863] [ruby-trunk - Feature #10344] [PATCH] Implement Fiber#raise
       [not found] <redmine.issue-10344.20141009002911@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2014-10-23  1:05 ` [ruby-core:65862] " ko1
@ 2014-10-23  1:08 ` ko1
  2014-10-24 16:16 ` [ruby-core:65892] " Knut.Franke
                   ` (11 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: ko1 @ 2014-10-23  1:08 UTC (permalink / raw
  To: ruby-core

Issue #10344 has been updated by Koichi Sasada.


Knut Franke wrote:
> > I understand this feature helps some libraries. But I can't understand why it is important.
> 
> Without Fiber#raise, libraries need to use some rather inelegant and inefficient workarounds (wrapping or tagging exceptions, wrapping Fiber.yield etc).

I understand.

> Also, having Thread#raise arguably leads one to expect the same functionality in Fiber. I'm not sure whether the feature qualifies as "important", but I still think it is worth including.

I don't expect there is Fiber#raise. Fiber and Thread are different.

> > Basically, I want to recommend strongly that using Fiber as semi-croutine, ristricted feature.
> 
> I think [Consumer](http://nome.github.io/coroutines/Consumer.html) is an example of a semi-coroutine (in the sense that it uses Fiber.yield, not Fiber#transfer) that benefits from having Fiber#raise.

Interesting. I don't know details of this library. Could you explain why it is important in this library?


----------------------------------------
Feature #10344: [PATCH] Implement Fiber#raise
https://bugs.ruby-lang.org/issues/10344#change-49598

* Author: Knut Franke
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
While it is possible to implement this in pure Ruby (by wrapping Fiber.yield and Fiber#resume), this feels like a low-level feature that ought to be provided out of the box. Also, the C implementation is more straight-forward, and more efficient. Unfortunately, it is not quite possible to implement this as a C extension module (without resorting to wrappers again); cf. the change to make_passing_arg().

Example usage:

~~~
fib = Fiber.new do
  counter = 0
  loop { counter += Fiber.yield }
  counter
end
fib.resume
fib.resume 10
fib.resume 100
fib.raise StopIteration # => 110
~~~

---Files--------------------------------
0001-Implement-Fiber-raise.patch (4.12 KB)
0001-Implement-Fiber-raise.patch (3.51 KB)
0001-Implement-Fiber-raise-in-ext-fiber.patch (3.6 KB)


-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:65892] [ruby-trunk - Feature #10344] [PATCH] Implement Fiber#raise
       [not found] <redmine.issue-10344.20141009002911@ruby-lang.org>
                   ` (8 preceding siblings ...)
  2014-10-23  1:08 ` [ruby-core:65863] " ko1
@ 2014-10-24 16:16 ` Knut.Franke
  2017-09-19  9:07 ` [ruby-core:82870] [Ruby trunk Feature#10344] " yugui
                   ` (10 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: Knut.Franke @ 2014-10-24 16:16 UTC (permalink / raw
  To: ruby-core

Issue #10344 has been updated by Knut Franke.


Koichi Sasada wrote:
> > I think [Consumer](http://nome.github.io/coroutines/Consumer.html) is an example of a semi-coroutine (in the sense that it uses Fiber.yield, not Fiber#transfer) that benefits from having Fiber#raise.
> 
> Interesting. I don't know details of this library. Could you explain why it is important in this library?

Consumer provides an abstraction for (semi-)coroutines that accept (consume) values; analogous to an Enumerator, which produces (enumerates) values. Since a consumer may need to do resource cleanup and/or produce a final result, we need some way to signal end of values. I think the most natural way to do this is to raise StopIteration in the consumer: The situation is analogous to calling Enumerator#next when no more values are available, and StopIteration terminates Kernel#loop, which often allows writing consumers very concisely.

In general, I think Fiber is a powerful primitive that can be used by libraries to build abstractions like Enumerator, Consumer and others. While Enumerator does not require the #raise feature, other abstractions can very well benefit from it.

----------------------------------------
Feature #10344: [PATCH] Implement Fiber#raise
https://bugs.ruby-lang.org/issues/10344#change-49634

* Author: Knut Franke
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
While it is possible to implement this in pure Ruby (by wrapping Fiber.yield and Fiber#resume), this feels like a low-level feature that ought to be provided out of the box. Also, the C implementation is more straight-forward, and more efficient. Unfortunately, it is not quite possible to implement this as a C extension module (without resorting to wrappers again); cf. the change to make_passing_arg().

Example usage:

~~~
fib = Fiber.new do
  counter = 0
  loop { counter += Fiber.yield }
  counter
end
fib.resume
fib.resume 10
fib.resume 100
fib.raise StopIteration # => 110
~~~

---Files--------------------------------
0001-Implement-Fiber-raise.patch (4.12 KB)
0001-Implement-Fiber-raise.patch (3.51 KB)
0001-Implement-Fiber-raise-in-ext-fiber.patch (3.6 KB)


-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:82870] [Ruby trunk Feature#10344] [PATCH] Implement Fiber#raise
       [not found] <redmine.issue-10344.20141009002911@ruby-lang.org>
                   ` (9 preceding siblings ...)
  2014-10-24 16:16 ` [ruby-core:65892] " Knut.Franke
@ 2017-09-19  9:07 ` yugui
  2018-12-12  1:51 ` [ruby-core:90431] " samuel
                   ` (9 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: yugui @ 2017-09-19  9:07 UTC (permalink / raw
  To: ruby-core

Issue #10344 has been updated by yugui (Yuki Sonoda).

Assignee set to ko1 (Koichi Sasada)
Target version set to 2.5

Let me add another use case which I discussed with naruse and akr in RubyKaigi.

`Fiber#raise` is helpful to improve compatibility of methods with blocks (internal iterators) and `Enumerator` (external iterators).
This happened for me when I tried to write an adapter between two independently-developed APIs.

Here's a simplified example below.  You can also find the real example in https://github.com/supership-jp/activerecord-spanner-adapter/blob/master/lib/active_record/connection_adapters/spanner/client.rb.

# Example
Suppose that we have a third-paty API, which we cannot control.

```
def with_transaction
  tx = Transaction.new
  begin
    yield tx
  rescue
    tx.rollback
  else
    tx.commit
  end
end
```

And now I need to begin a transaction in a method and then need to commit or rollback the transaction in other methods.

```
class TransactionManager
  def begin_transaction
     @iter = Transaction.enum_for(:begin_transaction)
     @tx = @iter.next # skip error handlings for simplicity
  end

  def commit_transaction
    loop { @iter.next }
  ensure
    @tx = nil
  end

  def abort_transaction(reason = RuntimeError.new)
    # ??? How can I let the iterator know the error raised
    @iter.raise(reason)
  end
  
  attr_reader :tx
end
```

In other words, internal iterators in Ruby can manage resources in it but external iterators can't even if the user tried to take responsibility of calling cleanup mechanism.
In the real usecase, `with_transaction` was an API given by `google-cloud-spanner` gem and the interface of the `TransactionManager` was the one I had to implement for ActiveRecord.

# Proposal
Although I could certainly implement the adapter without the native `Fiber#raise`, it would be still helpful if internal iterators and external iterators in Ruby were more consistent.

Can we have `Fiber#raise` and `Enumerator#raise` on top of it to improve the consistency? ko1?

FYI: I've confirmed that the patch by nome still works fine for ruby-trunk.  https://github.com/yugui/ruby/commit/5a04a8b49b5086686fd75c6635c95c12ccc6caa8

----------------------------------------
Feature #10344: [PATCH] Implement Fiber#raise
https://bugs.ruby-lang.org/issues/10344#change-66770

* Author: nome (Knut Franke)
* Status: Open
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Target version: 2.5
----------------------------------------
While it is possible to implement this in pure Ruby (by wrapping Fiber.yield and Fiber#resume), this feels like a low-level feature that ought to be provided out of the box. Also, the C implementation is more straight-forward, and more efficient. Unfortunately, it is not quite possible to implement this as a C extension module (without resorting to wrappers again); cf. the change to make_passing_arg().

Example usage:

~~~
fib = Fiber.new do
  counter = 0
  loop { counter += Fiber.yield }
  counter
end
fib.resume
fib.resume 10
fib.resume 100
fib.raise StopIteration # => 110
~~~

---Files--------------------------------
0001-Implement-Fiber-raise.patch (4.12 KB)
0001-Implement-Fiber-raise.patch (3.51 KB)
0001-Implement-Fiber-raise-in-ext-fiber.patch (3.6 KB)


-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:90431] [Ruby trunk Feature#10344] [PATCH] Implement Fiber#raise
       [not found] <redmine.issue-10344.20141009002911@ruby-lang.org>
                   ` (10 preceding siblings ...)
  2017-09-19  9:07 ` [ruby-core:82870] [Ruby trunk Feature#10344] " yugui
@ 2018-12-12  1:51 ` samuel
  2018-12-12  1:52 ` [ruby-core:90432] " samuel
                   ` (8 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: samuel @ 2018-12-12  1:51 UTC (permalink / raw
  To: ruby-core

Issue #10344 has been updated by ioquatix (Samuel Williams).


I think this is a good idea. I already ended up implementing it by hand, but it's messy.

https://github.com/socketry/async/blob/e169aac7bc47f251ae7c6ebe94820b41bc2d063f/lib/async/task.rb#L43-L55

----------------------------------------
Feature #10344: [PATCH] Implement Fiber#raise
https://bugs.ruby-lang.org/issues/10344#change-75585

* Author: nome (Knut Franke)
* Status: Open
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Target version: 
----------------------------------------
While it is possible to implement this in pure Ruby (by wrapping Fiber.yield and Fiber#resume), this feels like a low-level feature that ought to be provided out of the box. Also, the C implementation is more straight-forward, and more efficient. Unfortunately, it is not quite possible to implement this as a C extension module (without resorting to wrappers again); cf. the change to make_passing_arg().

Example usage:

~~~
fib = Fiber.new do
  counter = 0
  loop { counter += Fiber.yield }
  counter
end
fib.resume
fib.resume 10
fib.resume 100
fib.raise StopIteration # => 110
~~~

---Files--------------------------------
0001-Implement-Fiber-raise.patch (4.12 KB)
0001-Implement-Fiber-raise.patch (3.51 KB)
0001-Implement-Fiber-raise-in-ext-fiber.patch (3.6 KB)


-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:90432] [Ruby trunk Feature#10344] [PATCH] Implement Fiber#raise
       [not found] <redmine.issue-10344.20141009002911@ruby-lang.org>
                   ` (11 preceding siblings ...)
  2018-12-12  1:51 ` [ruby-core:90431] " samuel
@ 2018-12-12  1:52 ` samuel
  2018-12-20  1:11 ` [ruby-core:90626] [Ruby trunk Feature#10344][Assigned] " samuel
                   ` (7 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: samuel @ 2018-12-12  1:52 UTC (permalink / raw
  To: ruby-core

Issue #10344 has been updated by ioquatix (Samuel Williams).


@ko1 do you think we can aim for 2.6? I don't mind reviewing this patch and merging it if you are happy with it.

----------------------------------------
Feature #10344: [PATCH] Implement Fiber#raise
https://bugs.ruby-lang.org/issues/10344#change-75586

* Author: nome (Knut Franke)
* Status: Open
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Target version: 
----------------------------------------
While it is possible to implement this in pure Ruby (by wrapping Fiber.yield and Fiber#resume), this feels like a low-level feature that ought to be provided out of the box. Also, the C implementation is more straight-forward, and more efficient. Unfortunately, it is not quite possible to implement this as a C extension module (without resorting to wrappers again); cf. the change to make_passing_arg().

Example usage:

~~~
fib = Fiber.new do
  counter = 0
  loop { counter += Fiber.yield }
  counter
end
fib.resume
fib.resume 10
fib.resume 100
fib.raise StopIteration # => 110
~~~

---Files--------------------------------
0001-Implement-Fiber-raise.patch (4.12 KB)
0001-Implement-Fiber-raise.patch (3.51 KB)
0001-Implement-Fiber-raise-in-ext-fiber.patch (3.6 KB)


-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:90626] [Ruby trunk Feature#10344][Assigned] [PATCH] Implement Fiber#raise
       [not found] <redmine.issue-10344.20141009002911@ruby-lang.org>
                   ` (12 preceding siblings ...)
  2018-12-12  1:52 ` [ruby-core:90432] " samuel
@ 2018-12-20  1:11 ` samuel
  2018-12-28 13:04 ` [ruby-core:90773] [Ruby trunk Feature#10344] " samuel
                   ` (6 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: samuel @ 2018-12-20  1:11 UTC (permalink / raw
  To: ruby-core

Issue #10344 has been updated by ioquatix (Samuel Williams).

Status changed from Open to Assigned
Assignee changed from ko1 (Koichi Sasada) to ioquatix (Samuel Williams)
Target version set to next minor

We will experiment and aim to merge this into 2.7

----------------------------------------
Feature #10344: [PATCH] Implement Fiber#raise
https://bugs.ruby-lang.org/issues/10344#change-75789

* Author: nome (Knut Franke)
* Status: Assigned
* Priority: Normal
* Assignee: ioquatix (Samuel Williams)
* Target version: next minor
----------------------------------------
While it is possible to implement this in pure Ruby (by wrapping Fiber.yield and Fiber#resume), this feels like a low-level feature that ought to be provided out of the box. Also, the C implementation is more straight-forward, and more efficient. Unfortunately, it is not quite possible to implement this as a C extension module (without resorting to wrappers again); cf. the change to make_passing_arg().

Example usage:

~~~
fib = Fiber.new do
  counter = 0
  loop { counter += Fiber.yield }
  counter
end
fib.resume
fib.resume 10
fib.resume 100
fib.raise StopIteration # => 110
~~~

---Files--------------------------------
0001-Implement-Fiber-raise.patch (4.12 KB)
0001-Implement-Fiber-raise.patch (3.51 KB)
0001-Implement-Fiber-raise-in-ext-fiber.patch (3.6 KB)


-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:90773] [Ruby trunk Feature#10344] [PATCH] Implement Fiber#raise
       [not found] <redmine.issue-10344.20141009002911@ruby-lang.org>
                   ` (13 preceding siblings ...)
  2018-12-20  1:11 ` [ruby-core:90626] [Ruby trunk Feature#10344][Assigned] " samuel
@ 2018-12-28 13:04 ` samuel
  2018-12-30 15:48 ` [ruby-core:90826] " naruse
                   ` (5 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: samuel @ 2018-12-28 13:04 UTC (permalink / raw
  To: ruby-core

Issue #10344 has been updated by ioquatix (Samuel Williams).


@nome can you review the relevant commits and give me feedback?

----------------------------------------
Feature #10344: [PATCH] Implement Fiber#raise
https://bugs.ruby-lang.org/issues/10344#change-75947

* Author: nome (Knut Franke)
* Status: Closed
* Priority: Normal
* Assignee: ioquatix (Samuel Williams)
* Target version: 2.7
----------------------------------------
While it is possible to implement this in pure Ruby (by wrapping Fiber.yield and Fiber#resume), this feels like a low-level feature that ought to be provided out of the box. Also, the C implementation is more straight-forward, and more efficient. Unfortunately, it is not quite possible to implement this as a C extension module (without resorting to wrappers again); cf. the change to make_passing_arg().

Example usage:

~~~
fib = Fiber.new do
  counter = 0
  loop { counter += Fiber.yield }
  counter
end
fib.resume
fib.resume 10
fib.resume 100
fib.raise StopIteration # => 110
~~~

---Files--------------------------------
0001-Implement-Fiber-raise.patch (4.12 KB)
0001-Implement-Fiber-raise.patch (3.51 KB)
0001-Implement-Fiber-raise-in-ext-fiber.patch (3.6 KB)


-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:90826] [Ruby trunk Feature#10344] [PATCH] Implement Fiber#raise
       [not found] <redmine.issue-10344.20141009002911@ruby-lang.org>
                   ` (14 preceding siblings ...)
  2018-12-28 13:04 ` [ruby-core:90773] [Ruby trunk Feature#10344] " samuel
@ 2018-12-30 15:48 ` naruse
  2018-12-30 17:44 ` [ruby-core:90827] " ko1
                   ` (4 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: naruse @ 2018-12-30 15:48 UTC (permalink / raw
  To: ruby-core

Issue #10344 has been updated by naruse (Yui NARUSE).


@ioquantix Is this feature accepted by matz?
A change which is visible from Ruby and non trivial bugs requires matz's approval.

And also you need to add description to NEWS if you add new feature.

----------------------------------------
Feature #10344: [PATCH] Implement Fiber#raise
https://bugs.ruby-lang.org/issues/10344#change-76009

* Author: nome (Knut Franke)
* Status: Closed
* Priority: Normal
* Assignee: ioquatix (Samuel Williams)
* Target version: 2.7
----------------------------------------
While it is possible to implement this in pure Ruby (by wrapping Fiber.yield and Fiber#resume), this feels like a low-level feature that ought to be provided out of the box. Also, the C implementation is more straight-forward, and more efficient. Unfortunately, it is not quite possible to implement this as a C extension module (without resorting to wrappers again); cf. the change to make_passing_arg().

Example usage:

~~~
fib = Fiber.new do
  counter = 0
  loop { counter += Fiber.yield }
  counter
end
fib.resume
fib.resume 10
fib.resume 100
fib.raise StopIteration # => 110
~~~

---Files--------------------------------
0001-Implement-Fiber-raise.patch (4.12 KB)
0001-Implement-Fiber-raise.patch (3.51 KB)
0001-Implement-Fiber-raise-in-ext-fiber.patch (3.6 KB)


-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:90827] [Ruby trunk Feature#10344] [PATCH] Implement Fiber#raise
       [not found] <redmine.issue-10344.20141009002911@ruby-lang.org>
                   ` (15 preceding siblings ...)
  2018-12-30 15:48 ` [ruby-core:90826] " naruse
@ 2018-12-30 17:44 ` ko1
  2018-12-30 21:56 ` [ruby-core:90831] " samuel
                   ` (3 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: ko1 @ 2018-12-30 17:44 UTC (permalink / raw
  To: ruby-core

Issue #10344 has been updated by ko1 (Koichi Sasada).


naruse (Yui NARUSE) wrote:
> @ioquatix Is this feature accepted by matz?
> A change which is visible from Ruby and non trivial bugs requires matz's approval.

this is a support comment.

Matz agreed this feature several years ago (maybe I'm only person against, and I also agree to introduce this feature now, except naming issue. but nobody except me has no objection :p)
I'm not sure about naming issue, but he doesn't say anything last time.

Anyway, it is safe to discuss at next dev meeting (I will speak for Samuel).

Thanks,
Koichi

----------------------------------------
Feature #10344: [PATCH] Implement Fiber#raise
https://bugs.ruby-lang.org/issues/10344#change-76010

* Author: nome (Knut Franke)
* Status: Closed
* Priority: Normal
* Assignee: ioquatix (Samuel Williams)
* Target version: 2.7
----------------------------------------
While it is possible to implement this in pure Ruby (by wrapping Fiber.yield and Fiber#resume), this feels like a low-level feature that ought to be provided out of the box. Also, the C implementation is more straight-forward, and more efficient. Unfortunately, it is not quite possible to implement this as a C extension module (without resorting to wrappers again); cf. the change to make_passing_arg().

Example usage:

~~~
fib = Fiber.new do
  counter = 0
  loop { counter += Fiber.yield }
  counter
end
fib.resume
fib.resume 10
fib.resume 100
fib.raise StopIteration # => 110
~~~

---Files--------------------------------
0001-Implement-Fiber-raise.patch (4.12 KB)
0001-Implement-Fiber-raise.patch (3.51 KB)
0001-Implement-Fiber-raise-in-ext-fiber.patch (3.6 KB)


-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:90831] [Ruby trunk Feature#10344] [PATCH] Implement Fiber#raise
       [not found] <redmine.issue-10344.20141009002911@ruby-lang.org>
                   ` (16 preceding siblings ...)
  2018-12-30 17:44 ` [ruby-core:90827] " ko1
@ 2018-12-30 21:56 ` samuel
  2018-12-31  5:00 ` [ruby-core:90834] " naruse
                   ` (2 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: samuel @ 2018-12-30 21:56 UTC (permalink / raw
  To: ruby-core

Issue #10344 has been updated by ioquatix (Samuel Williams).


Thanks I didn’t know approval procedure.

I will update NEWS one I’m sure the feature has stabilised.

----------------------------------------
Feature #10344: [PATCH] Implement Fiber#raise
https://bugs.ruby-lang.org/issues/10344#change-76015

* Author: nome (Knut Franke)
* Status: Closed
* Priority: Normal
* Assignee: ioquatix (Samuel Williams)
* Target version: 2.7
----------------------------------------
While it is possible to implement this in pure Ruby (by wrapping Fiber.yield and Fiber#resume), this feels like a low-level feature that ought to be provided out of the box. Also, the C implementation is more straight-forward, and more efficient. Unfortunately, it is not quite possible to implement this as a C extension module (without resorting to wrappers again); cf. the change to make_passing_arg().

Example usage:

~~~
fib = Fiber.new do
  counter = 0
  loop { counter += Fiber.yield }
  counter
end
fib.resume
fib.resume 10
fib.resume 100
fib.raise StopIteration # => 110
~~~

---Files--------------------------------
0001-Implement-Fiber-raise.patch (4.12 KB)
0001-Implement-Fiber-raise.patch (3.51 KB)
0001-Implement-Fiber-raise-in-ext-fiber.patch (3.6 KB)


-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:90834] [Ruby trunk Feature#10344] [PATCH] Implement Fiber#raise
       [not found] <redmine.issue-10344.20141009002911@ruby-lang.org>
                   ` (17 preceding siblings ...)
  2018-12-30 21:56 ` [ruby-core:90831] " samuel
@ 2018-12-31  5:00 ` naruse
  2019-05-28 11:26 ` [ruby-core:92875] " fg
  2019-09-14 21:49 ` [ruby-core:94938] [Ruby master " samuel
  20 siblings, 0 replies; 23+ messages in thread
From: naruse @ 2018-12-31  5:00 UTC (permalink / raw
  To: ruby-core

Issue #10344 has been updated by naruse (Yui NARUSE).


ko1 (Koichi Sasada) wrote:
> naruse (Yui NARUSE) wrote:
> > @ioquatix Is this feature accepted by matz?
> > A change which is visible from Ruby and non trivial bugs requires matz's approval.
> 
> this is a support comment.
> 
> Matz agreed this feature several years ago (maybe I'm only person against, and I also agree to introduce this feature now, except naming issue. but nobody except me has no objection :p)
> I'm not sure about naming issue, but he doesn't say anything last time.
> 
> Anyway, it is safe to discuss at next dev meeting (I will speak for Samuel).

Sure, thank you for comment.

ioquatix (Samuel Williams) wrote:
> Thanks I didn’t know approval procedure.
> 
> I will update NEWS one I’m sure the feature has stabilised.

Anyway please update NEWS now to avoid forgetting adding the description.

----------------------------------------
Feature #10344: [PATCH] Implement Fiber#raise
https://bugs.ruby-lang.org/issues/10344#change-76017

* Author: nome (Knut Franke)
* Status: Closed
* Priority: Normal
* Assignee: ioquatix (Samuel Williams)
* Target version: 2.7
----------------------------------------
While it is possible to implement this in pure Ruby (by wrapping Fiber.yield and Fiber#resume), this feels like a low-level feature that ought to be provided out of the box. Also, the C implementation is more straight-forward, and more efficient. Unfortunately, it is not quite possible to implement this as a C extension module (without resorting to wrappers again); cf. the change to make_passing_arg().

Example usage:

~~~
fib = Fiber.new do
  counter = 0
  loop { counter += Fiber.yield }
  counter
end
fib.resume
fib.resume 10
fib.resume 100
fib.raise StopIteration # => 110
~~~

---Files--------------------------------
0001-Implement-Fiber-raise.patch (4.12 KB)
0001-Implement-Fiber-raise.patch (3.51 KB)
0001-Implement-Fiber-raise-in-ext-fiber.patch (3.6 KB)


-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:92875] [Ruby trunk Feature#10344] [PATCH] Implement Fiber#raise
       [not found] <redmine.issue-10344.20141009002911@ruby-lang.org>
                   ` (18 preceding siblings ...)
  2018-12-31  5:00 ` [ruby-core:90834] " naruse
@ 2019-05-28 11:26 ` fg
  2019-09-14 21:49 ` [ruby-core:94938] [Ruby master " samuel
  20 siblings, 0 replies; 23+ messages in thread
From: fg @ 2019-05-28 11:26 UTC (permalink / raw
  To: ruby-core

Issue #10344 has been updated by decuplet (Nikita Shilnikov).


Shortly after I started to work on a library implementing algebraic effects (https://github.com/dry-rb/dry-effects) I stumbled upon lack of `Fiber#raise`. From the user POV it is important to signal improper use of effects with a meaningful stacktrace so they can quickly detect what's wrong. It's possible to emulate `#raise` with checks but it's quite inefficient and seems redundant. Thank you all folks for discussing and working on this, I hope it'll land in 2.7. If you're interested I can show a clear example but the task is almost identical to @ioquatix's one.

----------------------------------------
Feature #10344: [PATCH] Implement Fiber#raise
https://bugs.ruby-lang.org/issues/10344#change-78254

* Author: nome (Knut Franke)
* Status: Closed
* Priority: Normal
* Assignee: ioquatix (Samuel Williams)
* Target version: 2.7
----------------------------------------
While it is possible to implement this in pure Ruby (by wrapping Fiber.yield and Fiber#resume), this feels like a low-level feature that ought to be provided out of the box. Also, the C implementation is more straight-forward, and more efficient. Unfortunately, it is not quite possible to implement this as a C extension module (without resorting to wrappers again); cf. the change to make_passing_arg().

Example usage:

~~~
fib = Fiber.new do
  counter = 0
  loop { counter += Fiber.yield }
  counter
end
fib.resume
fib.resume 10
fib.resume 100
fib.raise StopIteration # => 110
~~~

---Files--------------------------------
0001-Implement-Fiber-raise.patch (4.12 KB)
0001-Implement-Fiber-raise.patch (3.51 KB)
0001-Implement-Fiber-raise-in-ext-fiber.patch (3.6 KB)


-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:94938] [Ruby master Feature#10344] [PATCH] Implement Fiber#raise
       [not found] <redmine.issue-10344.20141009002911@ruby-lang.org>
                   ` (19 preceding siblings ...)
  2019-05-28 11:26 ` [ruby-core:92875] " fg
@ 2019-09-14 21:49 ` samuel
  20 siblings, 0 replies; 23+ messages in thread
From: samuel @ 2019-09-14 21:49 UTC (permalink / raw
  To: ruby-core

Issue #10344 has been updated by ioquatix (Samuel Williams).


NEWS is updated.

----------------------------------------
Feature #10344: [PATCH] Implement Fiber#raise
https://bugs.ruby-lang.org/issues/10344#change-81554

* Author: nome (Knut Franke)
* Status: Closed
* Priority: Normal
* Assignee: ioquatix (Samuel Williams)
* Target version: 2.7
----------------------------------------
While it is possible to implement this in pure Ruby (by wrapping Fiber.yield and Fiber#resume), this feels like a low-level feature that ought to be provided out of the box. Also, the C implementation is more straight-forward, and more efficient. Unfortunately, it is not quite possible to implement this as a C extension module (without resorting to wrappers again); cf. the change to make_passing_arg().

Example usage:

~~~
fib = Fiber.new do
  counter = 0
  loop { counter += Fiber.yield }
  counter
end
fib.resume
fib.resume 10
fib.resume 100
fib.raise StopIteration # => 110
~~~

---Files--------------------------------
0001-Implement-Fiber-raise.patch (4.12 KB)
0001-Implement-Fiber-raise.patch (3.51 KB)
0001-Implement-Fiber-raise-in-ext-fiber.patch (3.6 KB)


-- 
https://bugs.ruby-lang.org/

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

end of thread, other threads:[~2019-09-14 21:49 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-10344.20141009002911@ruby-lang.org>
2014-10-09  0:29 ` [ruby-core:65537] [ruby-trunk - Feature #10344] [Open] [PATCH] Implement Fiber#raise Knut.Franke
2014-10-09  2:58 ` [ruby-core:65540] [ruby-trunk - Feature #10344] " ko1
2014-10-09 10:16 ` [ruby-core:65558] " funny.falcon
2014-10-11 16:28 ` [ruby-core:65618] " Knut.Franke
2014-10-16  4:36   ` [ruby-core:65747] " SASADA Koichi
2014-10-16  4:41 ` [ruby-core:65748] " ko1
2014-10-18 11:59   ` [ruby-core:65780] " Юрий Соколов
2014-10-18 12:11 ` [ruby-core:65781] " funny.falcon
2014-10-18 13:55 ` [ruby-core:65782] " Knut.Franke
2014-10-23  1:05 ` [ruby-core:65862] " ko1
2014-10-23  1:08 ` [ruby-core:65863] " ko1
2014-10-24 16:16 ` [ruby-core:65892] " Knut.Franke
2017-09-19  9:07 ` [ruby-core:82870] [Ruby trunk Feature#10344] " yugui
2018-12-12  1:51 ` [ruby-core:90431] " samuel
2018-12-12  1:52 ` [ruby-core:90432] " samuel
2018-12-20  1:11 ` [ruby-core:90626] [Ruby trunk Feature#10344][Assigned] " samuel
2018-12-28 13:04 ` [ruby-core:90773] [Ruby trunk Feature#10344] " samuel
2018-12-30 15:48 ` [ruby-core:90826] " naruse
2018-12-30 17:44 ` [ruby-core:90827] " ko1
2018-12-30 21:56 ` [ruby-core:90831] " samuel
2018-12-31  5:00 ` [ruby-core:90834] " naruse
2019-05-28 11:26 ` [ruby-core:92875] " fg
2019-09-14 21:49 ` [ruby-core:94938] [Ruby master " samuel

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).