From f65ed6ce2535920558ca62de3acbcb7415c2de06 Mon Sep 17 00:00:00 2001 From: Anuj Dutta Date: Mon, 23 Apr 2012 06:34:19 +0000 Subject: [PATCH] Added an example for Fiber transfer. --- cont.c | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-) diff --git a/cont.c b/cont.c index 97602ad..d900d5a 100644 --- a/cont.c +++ b/cont.c @@ -1425,6 +1425,32 @@ rb_fiber_m_resume(int argc, VALUE *argv, VALUE fib) * You cannot resume a fiber that transferred control to another one. * This will cause a double resume error. You need to transfer control * back to this fiber before it can yield and resume. + * + * Example: + * + * fiber1 = Fiber.new do + * puts "In Fiber 1" + * Fiber.yield + * end + * + * fiber2 = Fiber.new do + * puts "In Fiber 2" + * fiber1.transfer + * end + * + * fiber3 = Fiber.new do + * puts "In Fiber 3" + * end + * + * fiber2.resume + * fiber3.resume + * + * produces + * + * I am in fiber2 + * I am in fiber1 + * I am in fiber3 + * */ static VALUE rb_fiber_m_transfer(int argc, VALUE *argv, VALUE fibval) -- 1.7.4.4