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