lib/falcon/controller/serve.rb in falcon-0.36.4 vs lib/falcon/controller/serve.rb in falcon-0.36.5

- old
+ new

@@ -27,49 +27,61 @@ require 'async/io/shared_endpoint' module Falcon module Controller + # A generic controller for serving an application. + # Uses {Server} for handling incoming requests. class Serve < Async::Container::Controller + # Initialize the server controller. + # @parameter command [Command::Serve] The user-specified command-line options. def initialize(command, **options) @command = command @endpoint = nil @bound_endpoint = nil @debug_trap = Async::IO::Trap.new(:USR1) super(**options) end + # Create the controller as specified by the command. + # e.g. `Async::Container::Forked`. def create_container @command.container_class.new end + # The endpoint the server will bind to. def endpoint @command.endpoint end + # @returns [Protocol::HTTP::Middleware] an instance of the application to be served. def load_app @command.load_app end + # Prepare the bound endpoint for the server. def start @endpoint ||= self.endpoint - @bound_endpoint = Async::Reactor.run do + @bound_endpoint = Async do Async::IO::SharedEndpoint.bound(@endpoint) end.wait @debug_trap.ignore! super end + # The name of the controller which is used for the process title. def name "Falcon Server" end + # Setup the container with the application instance. + # @parameter container [Async::Container::Generic] def setup(container) container.run(name: self.name, restart: true, **@command.container_options) do |instance| Async do |task| # Load one app instance per container: app = self.load_app @@ -97,9 +109,10 @@ task.children.each(&:wait) end end end + # Close the bound endpoint. def stop(*) @bound_endpoint&.close @debug_trap.default!