class Handler
The falcon adaptor for the rackup executable.
Definitions
SCHEME = "http"
The default scheme.
def self.to_s
The name of the handler.
Implementation
def self.to_s
"Falcon v#{Falcon::VERSION}"
end
def self.endpoint_for(**options)
Generate an endpoint for the given rackup options.
Signature
-
returns
::IO::Endpoint::HostEndpoint
Implementation
def self.endpoint_for(**options)
host = options[:Host] || "localhost"
port = Integer(options[:Port] || 9292)
return ::IO::Endpoint.tcp(host, port)
end
def self.run(app, **options)
Run the specified app using the given options:
Signature
-
parameter
appObject The rack middleware.
Implementation
def self.run(app, **options)
app = ::Protocol::Rack::Adapter.new(app)
Sync do |task|
endpoint = endpoint_for(**options)
server = ::Falcon::Server.new(app, endpoint, protocol: Async::HTTP::Protocol::HTTP1, scheme: SCHEME)
server_task = server.run
wrapper = self.new(server, task)
yield wrapper if block_given?
server_task.wait
ensure
server_task.stop
wrapper.close
end
end
def initialize(server, task)
Initialize the handler with a server and task.
Signature
-
parameter
serverFalcon::Server The server instance.
-
parameter
taskAsync::Task The async task managing the server.
Implementation
def initialize(server, task)
@server = server
@task = task
@notification = Thread::Queue.new
@waiter = @task.async(transient: true) do
@notification.pop
@task&.stop
@task = nil
end
end
def stop
Signal the handler to stop the server.
Implementation
def stop
@notification&.push(true)
end
def close
Close the handler and clean up resources.
Implementation
def close
@notification&.close
@notification = nil
@waiter&.stop
@waiter = nil
end