diff options
author | Benoit Daloze <[email protected]> | 2022-12-20 23:02:25 +0100 |
---|---|---|
committer | Benoit Daloze <[email protected]> | 2022-12-20 23:05:56 +0100 |
commit | 33debffdd3aa0ef9752857530c125f0a889db970 () | |
tree | 0239b54b88841e730302ed577c574fed75f4ca32 /enumerator.c | |
parent | 4495dea153a097c59d56819bc827bebfbef5be3f (diff) |
Use "Fiber storage variables" consistently
Notes: Merged: https://.com/ruby/ruby/pull/6974
-rw-r--r-- | enumerator.c | 16 |
1 files changed, 8 insertions, 8 deletions
@@ -97,28 +97,28 @@ * - The stacktrace will only include the stack from the Enumerator, not above. * - Fiber-local variables are *not* inherited inside the Enumerator Fiber, * which instead starts with no Fiber-local variables. - * - Fiber-scoped variables *are* inherited and are designed - * to handle Enumerator Fibers. Assigning to a Fiber-scope variable * only affects the current Fiber, so if you want to change state * in the caller Fiber of the Enumerator Fiber, you need to use an - * extra indirection (e.g., use some object in the Fiber-scoped * variable and mutate some ivar of it). * * Concretely: * Thread.current[:fiber_local] = 1 - * Fiber[:scoped_var] = 1 * e = Enumerator.new do |y| * p Thread.current[:fiber_local] # for external iteration: nil, for internal iteration: 1 - * p Fiber[:scoped_var] # => 1, inherited - * Fiber[:scoped_var] += 1 * y << 42 * end * * p e.next # => 42 - * p Fiber[:scoped_var] # => 1 (it ran in a different Fiber) * * e.each { p _1 } - * p Fiber[:scoped_var] # => 2 (it ran in the same Fiber/"stack" as the current Fiber) * * == Convert External Iteration to Internal Iteration * |