class Rack::Handler::Falcon
The falcon adaptor for the ‘rackup` executable.
def self.endpoint_for(**options)
Generate an endpoint for the given `rackup` options.
def self.endpoint_for(**options) host = options[:Host] || 'localhost' port = Integer(options[:Port] || 9292) return Async::IO::Endpoint.tcp(host, port) end
def self.run(app, **options)
Run the specified app using the given options:
def self.run(app, **options) app = ::Falcon::Adapters::Rack.new(app) app = ::Falcon::Adapters::Rewindable.new(app) Sync do |task| endpoint = endpoint_for(**options) server = ::Falcon::Server.new(app, endpoint, protocol: Async::HTTP::Protocol::HTTP1, scheme: SCHEME) server_task = task.async do server.run.each(&:wait) end wrapper = self.new(server, task) yield wrapper if block_given? server_task.wait ensure server_task.stop wrapper.close end end
def close
def close @notification&.close @notification = nil @waiter&.stop @waiter = nil end
def initialize(server, task)
def initialize(server, task) @server = server @task = task @notification = Async::IO::Notification.new @waiter = @task.async(transient: true) do @notification.wait @task&.stop @task = nil end end
def stop
def stop @notification&.signal end