Created
October 23, 2022 14:25
-
-
Save havenwood/76365da1b444482561d58d53b002a62a to your computer and use it in GitHub Desktop.
A Rack 3 example of bidirectional streaming with Async HTTP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'async/http/internet' | |
Async do | |
internet = Async::HTTP::Internet.new | |
response = internet.get('http://localhost:9292') | |
stream = response.connection.stream | |
stream.write('Hello World!') | |
stream.close_write | |
puts response.read | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
def headers = {'content-type' => 'text/plain'} | |
STREAM = -> do | |
_1.write _1.read | |
ensure | |
_1.close | |
end | |
run do |_env| | |
[200, headers, STREAM] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment