Class: Rack::Handler::Falcon
- Inherits:
-
Object
- Object
- Rack::Handler::Falcon
- Defined in:
- lib/rack/handler/falcon.rb
Overview
The falcon adaptor for the ‘rackup` executable.
Constant Summary collapse
- SCHEME =
The default scheme.
"http"
Class Method Summary collapse
-
.endpoint_for(**options) ⇒ Object
Generate an endpoint for the given ‘rackup` options.
-
.run(app, **options) ⇒ Object
Run the specified app using the given options:.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(server, task) ⇒ Falcon
constructor
A new instance of Falcon.
- #stop ⇒ Object
Constructor Details
#initialize(server, task) ⇒ Falcon
Returns a new instance of Falcon.
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rack/handler/falcon.rb', line 55 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 |
Class Method Details
.endpoint_for(**options) ⇒ Object
Generate an endpoint for the given ‘rackup` options.
24 25 26 27 28 29 |
# File 'lib/rack/handler/falcon.rb', line 24 def self.endpoint_for(**) host = [:Host] || 'localhost' port = Integer([:Port] || 9292) return Async::IO::Endpoint.tcp(host, port) end |
.run(app, **options) ⇒ Object
Run the specified app using the given options:
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rack/handler/falcon.rb', line 33 def self.run(app, **) app = ::Protocol::Rack::Adapter.new(app) Sync do |task| endpoint = endpoint_for(**) 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 |
Instance Method Details
#close ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/rack/handler/falcon.rb', line 73 def close @notification&.close @notification = nil @waiter&.stop @waiter = nil end |
#stop ⇒ Object
69 70 71 |
# File 'lib/rack/handler/falcon.rb', line 69 def stop @notification&.signal end |