@@ -79,11 +79,13 @@ def with_server(request_handler, &block)
79
79
# Create ruby worker threads that process requests;
80
80
# 1 is usually enough, and generally handles better than multiple threads
81
81
# if there's no IO (because of the GIL)
82
- worker = Thread . new do
83
- server . run_worker do |request |
84
- # Process the request in Ruby
85
- # request is a hash with :method, :path, :headers, and :body keys
86
- request_handler . call ( request )
82
+ workers = 1 . times . map do
83
+ Thread . new do
84
+ server . run_worker do |request |
85
+ # Process the request in Ruby
86
+ # request is a hash with :method, :path, :headers, and :body keys
87
+ request_handler . call ( request )
88
+ end
87
89
end
88
90
end
89
91
@@ -92,7 +94,7 @@ def with_server(request_handler, &block)
92
94
93
95
ensure
94
96
server . stop if server
95
- worker . join if worker
97
+ workers . map ( & : join) if workers
96
98
end
97
99
98
100
def with_unix_socket_server ( request_handler , &block )
@@ -103,11 +105,13 @@ def with_unix_socket_server(request_handler, &block)
103
105
# Create ruby worker threads that process requests;
104
106
# 1 is usually enough, and generally handles better than multiple threads
105
107
# if there's no IO (because of the GIL)
106
- worker = Thread . new do
107
- server . run_worker do |request |
108
- # Process the request in Ruby
109
- # request is a hash with :method, :path, :headers, and :body keys
110
- request_handler . call ( request )
108
+ workers = 2 . times . map do
109
+ Thread . new do
110
+ server . run_worker do |request |
111
+ # Process the request in Ruby
112
+ # request is a hash with :method, :path, :headers, and :body keys
113
+ request_handler . call ( request )
114
+ end
111
115
end
112
116
end
113
117
@@ -117,7 +121,7 @@ def with_unix_socket_server(request_handler, &block)
117
121
118
122
ensure
119
123
server . stop if server
120
- worker . join if worker
124
+ workers . map ( & : join) if workers
121
125
end
122
126
123
127
def handler_simple ( request )
0 commit comments