Skip to content

Commit a1ab5bb

Browse files
committed
Add topics example.
1 parent d9bfc34 commit a1ab5bb

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

examples/topics.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env ruby
2+
3+
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4+
5+
require 'async'
6+
require 'faraday'
7+
require 'async/http/faraday'
8+
9+
# Async.logger.debug!
10+
11+
module TestAsync
12+
URL = 'https://www.google.com/search'
13+
TOPICS = %W{ruby python lisp javascript cobol}
14+
15+
def self.fetch_topics_async
16+
TOPICS.map do |topic|
17+
Async do
18+
Faraday.get("#{URL}?q=#{topic}")
19+
end
20+
end.map(&:wait)
21+
end
22+
end
23+
24+
Faraday.default_adapter = :async_http
25+
26+
Async do
27+
pp TestAsync.fetch_topics_async
28+
ensure
29+
Faraday.default_connection.close
30+
end
31+

0 commit comments

Comments
 (0)