From 799852d60b96f7110d84a8ee32299b3cd341e03b Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Mon, 20 May 2013 17:57:56 +0900 Subject: update Fiber.new doc --- mrbgems/mruby-fiber/src/fiber.c | 51 +++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/mrbgems/mruby-fiber/src/fiber.c b/mrbgems/mruby-fiber/src/fiber.c index 01410e4b3..befec3ee5 100644 --- a/mrbgems/mruby-fiber/src/fiber.c +++ b/mrbgems/mruby-fiber/src/fiber.c @@ -12,14 +12,51 @@ * * Creates an fiber, whose execution is suspend until it explicitly * resumed using Fibder#resume method. - * resume. Arguments passed to resume will be the value of - * the Fiber.yield expression or will be passed as block - * parameters to the fiber's block if this is the first resume. + * The code running inside the fiber can give up control by calling + * Fiber.yield in which case it yields control back to caller + * (the caller of the Fiber#resume). + * + * Upon yielding or termination the Fiber returns the value of the last + * executed expression + * + * For instance: + * + * fiber = Fiber.new do + * Fiber.yield 1 + * 2 + * end + * + * puts fiber.resume + * puts fiber.resume + * puts fiber.resume + * + * produces + * + * 1 + * 2 + * FiberError: dead fiber called + * + * The Fiber#resume method accepts an arbitrary number of + * parameters, if it is the first call to resume then they + * will be passed as block arguments. Otherwise they will be the return + * value of the call to Fiber.yield + * + * Example: + * + * fiber = Fiber.new do |first| + * second = Fiber.yield first + 2 + * end + * + * puts fiber.resume 10 + * puts fiber.resume 14 + * puts fiber.resume 18 + * + * produces + * + * 12 + * 14 + * FiberError: dead fiber called * - * Alternatively, when resume is called it evaluates to the arguments passed - * to the next Fiber.yield statement inside the fiber's block - * or to the block value if it runs to completion without any - * Fiber.yield */ static mrb_value fiber_init(mrb_state *mrb, mrb_value self) -- cgit v1.2.3