Try to fix RDoc markup for Enumerator
This commit is contained in:
parent
c182d46d24
commit
d93d786338
25
enumerator.c
25
enumerator.c
@ -73,7 +73,7 @@
|
||||
* puts %w[foo bar baz].map.with_index { |w, i| "#{i}:#{w}" }
|
||||
* # => ["0:foo", "1:bar", "2:baz"]
|
||||
*
|
||||
* == External Iteration
|
||||
* == External Iteration
|
||||
*
|
||||
* An Enumerator can also be used as an external iterator.
|
||||
* For example, Enumerator#next returns the next value of the iterator
|
||||
@ -93,18 +93,19 @@
|
||||
*
|
||||
* External iteration differs *significantly* from internal iteration
|
||||
* due to using a Fiber:
|
||||
* - The Fiber adds some overhead compared to internal enumeration.
|
||||
* - 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 storage variables *are* inherited and are designed
|
||||
* to handle Enumerator Fibers. Assigning to a Fiber storage 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 storage
|
||||
* variable and mutate some ivar of it).
|
||||
* - The Fiber adds some overhead compared to internal enumeration.
|
||||
* - 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 storage variables *are* inherited and are designed
|
||||
* to handle Enumerator Fibers. Assigning to a Fiber storage 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 storage
|
||||
* variable and mutate some ivar of it).
|
||||
*
|
||||
* Concretely:
|
||||
*
|
||||
* Thread.current[:fiber_local] = 1
|
||||
* Fiber[:storage_var] = 1
|
||||
* e = Enumerator.new do |y|
|
||||
@ -120,7 +121,7 @@
|
||||
* e.each { p _1 }
|
||||
* 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
|
||||
*
|
||||
* You can use an external iterator to implement an internal iterator as follows:
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user