Sha256: 7a27e7c3ec48d60dce6bd208515a01e89bcca762d52c4cd688f30534364c7bd5
Contents?: true
Size: 827 Bytes
Versions: 5
Compression:
Stored size: 827 Bytes
Contents
require 'thread' module Rack class Lock class Proxy < Struct.new(:target, :mutex) # :nodoc: def each target.each { |x| yield x } end def close target.close if target.respond_to?(:close) ensure mutex.unlock end def to_path target.to_path end def respond_to?(sym) sym.to_sym == :close || target.respond_to?(sym) end end FLAG = 'rack.multithread'.freeze def initialize(app, mutex = Mutex.new) @app, @mutex = app, mutex end def call(env) old, env[FLAG] = env[FLAG], false @mutex.lock response = @app.call(env) response[2] = Proxy.new(response[2], @mutex) response rescue Exception @mutex.unlock raise ensure env[FLAG] = old end end end
Version data entries
5 entries across 5 versions & 3 rubygems