Use "Fiber storage variables" consistently

This commit is contained in:
Benoit Daloze 2022-12-20 23:02:25 +01:00
parent 4495dea153
commit 33debffdd3
Notes: git 2022-12-20 22:06:14 +00:00
2 changed files with 10 additions and 10 deletions

4
cont.c
View File

@ -2153,7 +2153,7 @@ rb_fiber_storage_set(VALUE self, VALUE value)
/** /**
* call-seq: Fiber[key] -> value * call-seq: Fiber[key] -> value
* *
* Returns the value of the fiber-scoped variable identified by +key+. * Returns the value of the fiber storage variable identified by +key+.
* *
* The +key+ must be a symbol, and the value is set by Fiber#[]= or * The +key+ must be a symbol, and the value is set by Fiber#[]= or
* Fiber#store. * Fiber#store.
@ -2176,7 +2176,7 @@ rb_fiber_storage_aref(VALUE class, VALUE key)
/** /**
* call-seq: Fiber[key] = value * call-seq: Fiber[key] = value
* *
* Assign +value+ to the fiber-scoped variable identified by +key+. * Assign +value+ to the fiber storage variable identified by +key+.
* The variable is created if it doesn't exist. * The variable is created if it doesn't exist.
* *
* +key+ must be a Symbol, otherwise a TypeError is raised. * +key+ must be a Symbol, otherwise a TypeError is raised.

View File

@ -97,28 +97,28 @@
* - The stacktrace will only include the stack from the Enumerator, not above. * - The stacktrace will only include the stack from the Enumerator, not above.
* - Fiber-local variables are *not* inherited inside the Enumerator Fiber, * - Fiber-local variables are *not* inherited inside the Enumerator Fiber,
* which instead starts with no Fiber-local variables. * which instead starts with no Fiber-local variables.
* - Fiber-scoped variables *are* inherited and are designed * - Fiber storage variables *are* inherited and are designed
* to handle Enumerator Fibers. Assigning to a Fiber-scope variable * to handle Enumerator Fibers. Assigning to a Fiber storage variable
* only affects the current Fiber, so if you want to change state * 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 * in the caller Fiber of the Enumerator Fiber, you need to use an
* extra indirection (e.g., use some object in the Fiber-scoped * extra indirection (e.g., use some object in the Fiber storage
* variable and mutate some ivar of it). * variable and mutate some ivar of it).
* *
* Concretely: * Concretely:
* Thread.current[:fiber_local] = 1 * Thread.current[:fiber_local] = 1
* Fiber[:scoped_var] = 1 * Fiber[:storage_var] = 1
* e = Enumerator.new do |y| * e = Enumerator.new do |y|
* p Thread.current[:fiber_local] # for external iteration: nil, for internal iteration: 1 * p Thread.current[:fiber_local] # for external iteration: nil, for internal iteration: 1
* p Fiber[:scoped_var] # => 1, inherited * p Fiber[:storage_var] # => 1, inherited
* Fiber[:scoped_var] += 1 * Fiber[:storage_var] += 1
* y << 42 * y << 42
* end * end
* *
* p e.next # => 42 * p e.next # => 42
* p Fiber[:scoped_var] # => 1 (it ran in a different Fiber) * p Fiber[:storage_var] # => 1 (it ran in a different Fiber)
* *
* e.each { p _1 } * e.each { p _1 }
* p Fiber[:scoped_var] # => 2 (it ran in the same Fiber/"stack" as the current Fiber) * p Fiber[:storage_var] # => 2 (it ran in the same Fiber/"stack" as the current Fiber)
* *
* == Convert External Iteration to Internal Iteration * == Convert External Iteration to Internal Iteration
* *