Created
December 25, 2010 11:06
-
-
Save ignacy/754825 to your computer and use it in GitHub Desktop.
Useless fibers 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
fib = Fiber.new do | |
v = 0 | |
loop do | |
v += 1 | |
Fiber.yield v | |
v.times { print "-"} | |
puts v | |
end | |
end | |
# now lets call it: | |
# => 20.times { fib.resume } | |
# -1 | |
# --2 | |
# ---3 | |
# ----4 | |
# -----5 | |
# ------6 | |
# -------7 | |
# --------8 | |
# ---------9 | |
# ----------10 | |
# -----------11 | |
# ------------12 | |
# -------------13 | |
# --------------14 | |
# ---------------15 | |
# ----------------16 | |
# -----------------17 | |
# ------------------18 | |
# -------------------19 | |
# => 20 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment