Skip to content

Commit

Permalink
Purge references to async-io gem.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Apr 29, 2024
1 parent 8ea5916 commit 44f4f2e
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 161 deletions.
1 change: 0 additions & 1 deletion examples/benchmark/bake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
require 'async'
require 'async/process'
require 'async/clock'
require 'async/io/stream'
require 'async/http/endpoint'

def hello
Expand Down
3 changes: 0 additions & 3 deletions fixtures/server_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
require 'falcon/server'
require 'async/http/client'
require 'async/http/endpoint'
require 'async/io/ssl_socket'
require 'async/io/shared_endpoint'


module ServerContext
include Sus::Fixtures::Async::ReactorContext
Expand Down
2 changes: 1 addition & 1 deletion lib/falcon/environment/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def ipc_path
end

# The endpoint that will be used for communicating with the application server.
# @returns [Async::IO::Endpoint]
# @returns [::Falcon::ProxyEndpoint]
def endpoint
::Falcon::ProxyEndpoint.unix(ipc_path,
protocol: protocol,
Expand Down
4 changes: 2 additions & 2 deletions lib/falcon/environment/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def ipc_path
end

# The endpoint the supervisor will bind to.
# @returns [Async::IO::Endpoint]
# @returns [::IO::Endpoint::Generic]
def endpoint
Async::IO::Endpoint.unix(ipc_path)
::IO::Endpoint.unix(ipc_path)
end

# The service class to use for the supervisor.
Expand Down
10 changes: 5 additions & 5 deletions lib/falcon/proxy_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# Released under the MIT License.
# Copyright, 2019-2023, by Samuel Williams.

require 'async/io/unix_endpoint'
require 'io/endpoint/unix_endpoint'

module Falcon
# An endpoint suitable for proxing requests, typically via a unix pipe.
class ProxyEndpoint < Async::IO::Endpoint
class ProxyEndpoint < ::IO::Endpoint::Generic
# Initialize the proxy endpoint.
# @parameter endpoint [Async::IO::Endpoint] The endpoint which will be used for connecting/binding.
# @parameter endpoint [::IO::Endpoint::Generic] The endpoint which will be used for connecting/binding.
def initialize(endpoint, **options)
super(**options)

Expand All @@ -21,7 +21,7 @@ def to_s
end

# The actual endpoint for I/O.
# @attribute [Async::IO::Endpoint]
# @attribute [::IO::Endpoint::Generic]
attr :endpoint

# The protocol to use for this connection.
Expand Down Expand Up @@ -69,7 +69,7 @@ def each
# Create a proxy unix endpoint with the specific path.
# @returns [ProxyEndpoint]
def self.unix(path, **options)
self.new(::Async::IO::Endpoint.unix(path), **options)
self.new(::IO::Endpoint.unix(path), **options)
end
end
end
82 changes: 82 additions & 0 deletions lib/falcon/rackup/handler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2023, by Samuel Williams.

require 'rackup/handler'

require_relative '../../falcon'

require 'kernel/sync'
require 'io/endpoint/host_endpoint'

module Falcon
module Rackup
module Handler
# The falcon adaptor for the `rackup` executable.
class Falcon
# The default scheme.
SCHEME = "http"

# Generate an endpoint for the given `rackup` options.
# @returns [::IO::Endpoint::HostEndpoint]
def self.endpoint_for(**options)
host = options[:Host] || 'localhost'
port = Integer(options[:Port] || 9292)

return ::IO::Endpoint.tcp(host, port)
end

# Run the specified app using the given options:
# @parameter app [Object] The rack middleware.
def self.run(app, **options)
app = ::Protocol::Rack::Adapter.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

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

def stop
@notification&.push(true)
end

def close
@notification&.close
@notification = nil

@waiter&.stop
@waiter = nil
end
end
end
end
end
4 changes: 1 addition & 3 deletions lib/falcon/service/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
require 'process/metrics'
require 'json'

require 'async/io/endpoint'
require 'async/io/shared_endpoint'
require 'async/service/generic'

module Falcon
Expand Down Expand Up @@ -71,7 +69,7 @@ def setup(container)
container.run(name: self.name, restart: true, count: 1) do |instance|
Async do
@bound_endpoint.accept do |peer|
stream = Async::IO::Stream.new(peer)
stream = ::IO::Stream.new(peer)

while message = stream.gets("\0")
response = handle(JSON.parse(message, symbolize_names: true))
Expand Down
76 changes: 3 additions & 73 deletions lib/rack/handler/falcon.rb
Original file line number Diff line number Diff line change
@@ -1,84 +1,14 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2017-2023, by Samuel Williams.
# Copyright, 2019, by Bryan Powell.
# Copyright, 2023, by Samuel Williams.

require 'rack/handler'

require_relative '../../falcon'

require 'kernel/sync'
require 'async/io/host_endpoint'
require 'async/io/notification'
require_relative '../../falcon/rackup/handler'

module Rack
module Handler
# The falcon adaptor for the `rackup` executable.
class Falcon
# The default scheme.
SCHEME = "http"

# Generate an endpoint for the given `rackup` options.
# @returns [Async::IO::Endpoint]
def self.endpoint_for(**options)
host = options[:Host] || 'localhost'
port = Integer(options[:Port] || 9292)

return Async::IO::Endpoint.tcp(host, port)
end

# Run the specified app using the given options:
# @parameter app [Object] The rack middleware.
def self.run(app, **options)
app = ::Protocol::Rack::Adapter.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

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

def stop
@notification&.signal
end

def close
@notification&.close
@notification = nil

@waiter&.stop
@waiter = nil
end
end

register :falcon, Falcon
register :falcon, ::Falcon::Rackup::Handler
end
end
73 changes: 2 additions & 71 deletions lib/rackup/handler/falcon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,79 +5,10 @@

require 'rackup/handler'

require_relative '../../falcon'

require 'kernel/sync'
require 'async/io/host_endpoint'
require 'async/io/notification'
require_relative '../../falcon/rackup/handler'

module Rackup
module Handler
# The falcon adaptor for the `rackup` executable.
class Falcon
# The default scheme.
SCHEME = "http"

# Generate an endpoint for the given `rackup` options.
# @returns [Async::IO::Endpoint]
def self.endpoint_for(**options)
host = options[:Host] || 'localhost'
port = Integer(options[:Port] || 9292)

return Async::IO::Endpoint.tcp(host, port)
end

# Run the specified app using the given options:
# @parameter app [Object] The rack middleware.
def self.run(app, **options)
app = ::Protocol::Rack::Adapter.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

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

def stop
@notification&.signal
end

def close
@notification&.close
@notification = nil

@waiter&.stop
@waiter = nil
end
end

register :falcon, Falcon
register :falcon, ::Falcon::Rackup::Handler
end
end
4 changes: 2 additions & 2 deletions test/falcon/ssl_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
let(:protocol) {Async::HTTP::Protocol::HTTPS}

def make_server_endpoint(bound_endpoint)
Async::IO::SSLEndpoint.new(super, ssl_context: server_context)
::IO::Endpoint::SSLEndpoint.new(super, ssl_context: server_context)
end

def make_client_endpoint(bound_endpoint)
Async::IO::SSLEndpoint.new(super, ssl_context: client_context)
::IO::Endpoint::SSLEndpoint.new(super, ssl_context: client_context)
end

with "basic middleware" do
Expand Down

0 comments on commit 44f4f2e

Please sign in to comment.