Skip to content

Instantly share code, notes, and snippets.

@ignacy
Created December 25, 2010 11:06
Show Gist options
  • Save ignacy/754825 to your computer and use it in GitHub Desktop.
Save ignacy/754825 to your computer and use it in GitHub Desktop.
Useless fibers example
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