diff --git a/examples/http_client/spec/ione/http_client_spec.rb b/examples/http_client/spec/ione/http_client_spec.rb index f200bed..f9ea5c9 100644 --- a/examples/http_client/spec/ione/http_client_spec.rb +++ b/examples/http_client/spec/ione/http_client_spec.rb @@ -76,7 +76,7 @@ def await_server_start it 'sends a GET request with headers' do response = client.get("#{base_uri}/helloworld", 'Accept' => 'text/html').value - response.headers.should include('Content-Type' => 'text/html') + expect(response.headers['Content-Type']).to start_with 'text/html' response.body.should eq('

Hello, World!

') end end diff --git a/lib/ione/io/io_reactor.rb b/lib/ione/io/io_reactor.rb index c7835fa..695bae9 100644 --- a/lib/ione/io/io_reactor.rb +++ b/lib/ione/io/io_reactor.rb @@ -139,15 +139,7 @@ def start if @state == RUNNING_STATE return @started_promise elsif @state == STOPPING_STATE - # Does not pass - # return @stopped_promise.then_flat { start }.then(&Concurrent::Promises.method(:fullfilled_future)) - # .rescue { start }.flat - # Passes - # return @stopped_promise.then { start }.rescue { start }.flat - # Passes - return @stopped_promise.then_flat { start }.rescue { start } - # Should pass but it does not. Equivalent of the original code - # return fallback(@stopped_promise.then_flat { start }) { start } + return fallback(@stopped_promise.then_flat { start }) { start } else @state = RUNNING_STATE end @@ -368,6 +360,23 @@ def to_s state = state_constant_name.to_s.rpartition('_').first %(#<#{self.class.name} #{state}>) end + + private + + def fallback(future) + Concurrent::Promises.resolvable_future.tap do |f| + future.on_fulfillment!(&f.method(:fulfill)) + future.on_rejection! do |reason| + begin + ff = yield(reason) + ff.on_fulfilment!(&f.method(:fulfill)) + ff.on_rejection!(&f.method(:reject)) + rescue => e + f.reject(e) + end + end + end + end end # @private @@ -629,21 +638,6 @@ def tick def to_s %(#<#{self.class.name} @timers=[#{@pending_timers.values.map(&:to_s).join(', ')}]>) end - # - # private - # - # def fallback(future, &block) - # Concurrent::Promises.resolvable_future.tap do |f| - # future.on_fulfillment(&f.method(:fulfill)) - # future.on_rejection do |reason| - # ff = block.call(reason) - # ff.on_fulfilment(&f.method(:fulfill)) - # ff.on_rejection(&f.method(:reject)) - # rescue => e - # f.reject(e) - # end - # end - # end end end end