Created
September 17, 2011 22:09
-
-
Save timrandg/1224423 to your computer and use it in GitHub Desktop.
why do fibers do this?
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
#I am curious why a fiber returns the arguments when there are no more yield statements left to evaluate--see below. Why not return nil? | |
fiber = Fiber.new do |first, second| | |
Fiber.yield first + 30 | |
Fiber.yield first + 20 | |
end | |
p fiber.resume 10, 20 # => 40 | |
p fiber.resume 10, 20 # => 30 | |
p fiber.resume 10, 20 # => [10, 20] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Starting to see it more clearly now. I made an attempt to explain how I think it works below...is it accurate? Tim