lib/falcon/capybara/wrapper.rb in falcon-capybara-1.4.0 vs lib/falcon/capybara/wrapper.rb in falcon-capybara-1.5.0
- old
+ new
@@ -24,38 +24,27 @@
require 'falcon/endpoint'
require 'async/io/notification'
module Falcon
module Capybara
+ # Implements a wrapper for starting the Falcon server for Capybara.
class Wrapper
+ # @parameter scheme [String] The scheme for the server to bind to.
+ # e.g. `http` or `https`.
def initialize(scheme = "http")
- @job = nil
@scheme = scheme
-
- @job_available = Async::IO::Notification.new
- @job_complete = Async::IO::Notification.new
end
- def close
- @job_available.close
- @job_complete.close
- end
-
- def remote(&block)
- @job = block
- @job_available.signal
-
- Async do
- Async.logger.debug (self) {"Waiting for job completion..."}
- @job_complete.wait
- end.wait
- end
-
+ # Build a server endpoint using the given scheme.
def endpoint(host, port)
Falcon::Endpoint.parse("#{@scheme}://#{host}:#{port}")
end
+ # Run the Falcon server hosting the given rack application.
+ # @parameter rack_app [Proc] A Rack application.
+ # @parameter port [Integer] The port number to bind to.
+ # @parameter host [String] The local host to bind to.
def call(rack_app, port, host)
require 'async/reactor'
require 'falcon/server'
Async do |task|
@@ -67,25 +56,11 @@
endpoint = self.endpoint(host, port)
server = Falcon::Server.new(app, endpoint, endpoint.protocol, endpoint.scheme)
- task.async do
- Async.logger.debug (self) {"Running server..."}
- server.run
- end
-
- while true
- Async.logger.debug (self) {"Waiting for job..."}
- @job_available.wait while @job.nil?
-
- Async.logger.debug (self) {"Running job #{@job}"}
- @job.call
- @job = nil
-
- Async.logger.debug (self) {"Completing job #{@job}"}
- @job_complete.signal
- end
+ Async.logger.debug (self) {"Running server..."}
+ server.run
end
end
end
end
end