Skip to content

Commit c12f462

Browse files
authored
Let's be more specific w.r.t. Async::HTTP::Server#run. (#158)
1 parent 5e38b2a commit c12f462

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

lib/async/http/server.rb

+8-2
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,15 @@ def accept(peer, address, task: Task.current)
6464
ensure
6565
connection&.close
6666
end
67-
67+
68+
# @returns [Array(Async::Task)] The task that is running the server.
6869
def run
69-
@endpoint.accept(&self.method(:accept))
70+
Async do
71+
@endpoint.accept(&self.method(:accept))
72+
73+
# Wait for all children to finish:
74+
self.children.each(&:wait)
75+
end
7076
end
7177

7278
Traces::Provider(self) do

test/async/http/server.rb

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# frozen_string_literal: true
2+
3+
# Released under the MIT License.
4+
# Copyright, 2017-2024, by Samuel Williams.
5+
6+
require 'async/http/server'
7+
require 'async/http/endpoint'
8+
require 'sus/fixtures/async'
9+
10+
describe Async::HTTP::Server do
11+
include Sus::Fixtures::Async::ReactorContext
12+
13+
let(:endpoint) {Async::HTTP::Endpoint.parse('http://localhost:0')}
14+
let(:app) {Protocol::HTTP::Middleware::Okay}
15+
let(:server) {subject.new(app, endpoint)}
16+
17+
with '#run' do
18+
it "runs the server" do
19+
task = server.run
20+
21+
expect(task).to be_a(Async::Task)
22+
23+
task.stop
24+
end
25+
end
26+
end

0 commit comments

Comments
 (0)