Sha256: 04e096a5a53fb8f3273f7bc3b699f1cc85f6dccbf9469777581dbddfe4c7efcf
Contents?: true
Size: 773 Bytes
Versions: 6
Compression:
Stored size: 773 Bytes
Contents
# frozen_string_literal: true require 'fiber' module CottonTail module Queue # Queue Reader class Reader def self.spawn(queue, **kwargs) Thread.new { new(queue, **kwargs).start } end def initialize(queue, app:) @queue = queue @app = app end def fiber @fiber ||= Fiber.new do Fiber.yield @queue.pop until @queue.empty? && @queue.closed? end end def start call_next while fiber.alive? end private def call_next request = fiber.resume middleware.call([env, request, Response.new]) if request end def middleware @app.config.middleware end def env @app.env end end end end
Version data entries
6 entries across 6 versions & 1 rubygems