Class: Rack::Handler::Falcon

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(server, task) ⇒ Falcon

Returns a new instance of Falcon.



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rack/handler/falcon.rb', line 52

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.



20
21
22
23
24
25
# File 'lib/rack/handler/falcon.rb', line 20

def self.endpoint_for(**options)
	host = options[:Host] || 'localhost'
	port = Integer(options[:Port] || 9292)
	
	return Async::IO::Endpoint.tcp(host, port)
end

.run(app, **options) ⇒ Object

Run the specified app using the given options:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rack/handler/falcon.rb', line 29

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

Instance Method Details

#closeObject



70
71
72
73
74
75
76
# File 'lib/rack/handler/falcon.rb', line 70

def close
	@notification&.close
	@notification = nil

	@waiter&.stop
	@waiter = nil
end

#stopObject



66
67
68
# File 'lib/rack/handler/falcon.rb', line 66

def stop
	@notification&.signal
end