1 # -*- encoding: binary -*-
4 # a self-sufficient Queue implementation for Fiber-based concurrency
5 # models. This requires no external scheduler, so it may be used with
6 # Revactor as well as FiberSpawn and FiberPool.
7 class Rainbows::Fiber::Queue < Struct.new(:queue, :waiters)
8 def initialize(queue = [], waiters = [])
9 # move elements of the Queue into an Array
10 if queue.class.name == "Queue"
11 queue = queue.length.times.map { queue.pop }
17 # ah the joys of not having to deal with race conditions
19 waiters << Fiber.current
27 blocked = waiters.shift and blocked.resume
28 queue # not quite 100% compatible but no-one's looking :>