Skip to content

Instantly share code, notes, and snippets.

@etiennebarrie
Created May 25, 2020 21:14
Show Gist options
  • Select an option

  • Save etiennebarrie/a46be637a925d07aea64c8efcc5fabcc to your computer and use it in GitHub Desktop.

Select an option

Save etiennebarrie/a46be637a925d07aea64c8efcc5fabcc to your computer and use it in GitHub Desktop.
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