ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: funny.falcon@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:65781] [ruby-trunk - Feature #10344] [PATCH] Implement Fiber#raise
Date: Sat, 18 Oct 2014 12:11:28 +0000	[thread overview]
Message-ID: <redmine.journal-49517.20141018121128.f0199244990b72b1@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-10344.20141009002911@ruby-lang.org

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/

  parent reply	other threads:[~2014-10-18 12:26 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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 ` funny.falcon [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-49517.20141018121128.f0199244990b72b1@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).