Last active
December 23, 2015 04:49
-
-
Save mzdravkov/6582603 to your computer and use it in GitHub Desktop.
Ruby's fibers (lazy eval example)
This file contains 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
all_nums = Fiber.new do | |
num = 0 | |
while true | |
Fiber.yield num | |
num += 1 | |
end | |
end | |
all_nums.resume # => 0 | |
all_nums.resume # => 1 | |
all_nums.resume # => 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment