From 2e131bfd21f5ec5acc3c86233e5e292cec7aa67d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 26 Dec 2010 23:52:02 +0000 Subject: fiber/queue: unindent This also cleans up some constant resolution for the root Fiber class. --- lib/rainbows/fiber/queue.rb | 54 ++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/lib/rainbows/fiber/queue.rb b/lib/rainbows/fiber/queue.rb index e7118f3..f752a65 100644 --- a/lib/rainbows/fiber/queue.rb +++ b/lib/rainbows/fiber/queue.rb @@ -1,36 +1,30 @@ # -*- encoding: binary -*- # :enddoc: -module Rainbows - module Fiber - - # a self-sufficient Queue implementation for Fiber-based concurrency - # models. This requires no external scheduler, so it may be used with - # Revactor as well as FiberSpawn and FiberPool. - class Queue < Struct.new(:queue, :waiters) - - def initialize(queue = [], waiters = []) - # move elements of the Queue into an Array - if queue.class.name == "Queue" - queue = queue.length.times.map { queue.pop } - end - super queue, waiters - end - - def shift - # ah the joys of not having to deal with race conditions - if queue.empty? - waiters << ::Fiber.current - ::Fiber.yield - end - queue.shift - end - - def <<(obj) - queue << obj - blocked = waiters.shift and blocked.resume - queue # not quite 100% compatible but no-one's looking :> - end +# +# a self-sufficient Queue implementation for Fiber-based concurrency +# models. This requires no external scheduler, so it may be used with +# Revactor as well as FiberSpawn and FiberPool. +class Rainbows::Fiber::Queue < Struct.new(:queue, :waiters) + def initialize(queue = [], waiters = []) + # move elements of the Queue into an Array + if queue.class.name == "Queue" + queue = queue.length.times.map { queue.pop } + end + super queue, waiters + end + def shift + # ah the joys of not having to deal with race conditions + if queue.empty? + waiters << Fiber.current + Fiber.yield end + queue.shift + end + + def <<(obj) + queue << obj + blocked = waiters.shift and blocked.resume + queue # not quite 100% compatible but no-one's looking :> end end -- cgit v1.2.3-24-ge0c7