Created
May 25, 2020 21:14
-
-
Save etiennebarrie/a46be637a925d07aea64c8efcc5fabcc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Thread.current[:fiber_local] = :ok | |
| def enumerator | |
| Enumerator.new do |yielder| | |
| yielder.yield Thread.current[:fiber_local] | |
| end | |
| end | |
| p enumerator.next # => nil | |
| # which is explained by, can be reduced to: | |
| p Fiber.new { Thread.current[:fiber_local] }.resume # => nil | |
| p enumerator.to_a # => [:ok] | |
| p enumerator.first # => :ok | |
| enumerator.each do |value| | |
| p value # => :ok | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment