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