File tree Expand file tree Collapse file tree 4 files changed +37
-31
lines changed
rack-async-http-falcon-graphql-lazy-resolve Expand file tree Collapse file tree 4 files changed +37
-31
lines changed Original file line number Diff line number Diff line change @@ -2,5 +2,6 @@ source "https://rubygems.org"
2
2
3
3
gem "rack"
4
4
gem "falcon"
5
+ gem "thread-local"
5
6
gem "async-http"
6
7
gem "graphql"
Original file line number Diff line number Diff line change 1
1
GEM
2
2
remote: https://rubygems.org/
3
3
specs:
4
- async (1.28.7 )
4
+ async (1.29.0 )
5
5
console (~> 1.10 )
6
6
nio4r (~> 2.3 )
7
7
timers (~> 4.1 )
19
19
async-http (~> 0.53 )
20
20
async-io (1.30.2 )
21
21
async (~> 1.14 )
22
- async-pool (0.3.4 )
22
+ async-pool (0.3.5 )
23
23
async (~> 1.25 )
24
24
build-environment (1.13.0 )
25
- console (1.10 .1 )
25
+ console (1.11 .1 )
26
26
fiber-local
27
- falcon (0.37.2 )
27
+ falcon (0.37.3 )
28
28
async (~> 1.13 )
29
29
async-container (~> 0.16.0 )
30
30
async-http (~> 0.54.0 )
37
37
rack (>= 1.0 )
38
38
samovar (~> 2.1 )
39
39
fiber-local (1.0.0 )
40
- graphql (1.12.4 )
41
- graphql-batch (0.4.3 )
42
- graphql (>= 1.3 , < 2 )
43
- promise.rb (~> 0.7.2 )
44
- localhost (1.1.6 )
40
+ graphql (1.12.7 )
41
+ localhost (1.1.7 )
45
42
mapping (1.1.1 )
46
- nio4r (2.5.5 )
43
+ nio4r (2.5.7 )
47
44
process-metrics (0.2.1 )
48
45
console (~> 1.8 )
49
46
samovar (~> 2.1 )
50
- promise.rb (0.7.4 )
51
47
protocol-hpack (1.4.2 )
52
48
protocol-http (0.21.0 )
53
49
protocol-http1 (0.13.2 )
59
55
samovar (2.1.4 )
60
56
console (~> 1.0 )
61
57
mapping (~> 1.0 )
62
- timers (4.3.2 )
58
+ thread-local (1.1.0 )
59
+ timers (4.3.3 )
63
60
64
61
PLATFORMS
65
62
ruby
@@ -68,11 +65,8 @@ DEPENDENCIES
68
65
async-http
69
66
falcon
70
67
graphql
71
- graphql-batch
72
68
rack
73
-
74
- RUBY VERSION
75
- ruby 2.7.2p137
69
+ thread-local
76
70
77
71
BUNDLED WITH
78
- 2.1.4
72
+ 2.2.5
Original file line number Diff line number Diff line change 1
1
require_relative "schema"
2
2
3
+ require 'securerandom'
4
+
3
5
class App
4
6
def self . call ( env )
5
- puts "Request start"
6
-
7
- result = Schema . execute ( "query { one two three }" )
7
+ logger = Console . logger . with ( name : SecureRandom . uuid )
8
8
9
- puts "Request finish"
9
+ Async ( logger : logger ) do
10
+ result = Console . logger . measure ( self , "Schema.execute" ) do
11
+ Schema . execute ( "query { one two three }" )
12
+ end
10
13
11
- [ 200 , { } , [ result . to_json ] ]
14
+ [ 200 , { } , [ result . to_json ] ]
15
+ end . wait
12
16
end
13
17
end
Original file line number Diff line number Diff line change 1
1
require "async/http/internet"
2
+ require "thread/local"
2
3
3
4
class Query < GraphQL ::Schema ::Object
4
5
field :one , String , null : false
@@ -17,8 +18,16 @@ def three
17
18
Async { delay_2_data [ "url" ] }
18
19
end
19
20
21
+ module Internet
22
+ extend Thread ::Local
23
+
24
+ def self . local
25
+ Async ::HTTP ::Internet . new
26
+ end
27
+ end
28
+
20
29
def internet
21
- @_internet ||= Async :: HTTP :: Internet . new
30
+ Internet . instance
22
31
end
23
32
24
33
def delay_1_semaphore
@@ -32,21 +41,19 @@ def delay_2_semaphore
32
41
def delay_1_data
33
42
delay_1_semaphore . async do |task |
34
43
@_delay_1_data ||= begin
35
- puts "-> delay_1_data"
36
- data = JSON . parse ( internet . get ( "https://httpbin.org/delay/1" ) . read )
37
- puts "<- delay_1_data"
38
- data
44
+ Console . logger . measure ( self , "delay_1_data" ) do
45
+ JSON . parse ( internet . get ( "https://httpbin.org/delay/1" ) . read )
46
+ end
39
47
end
40
48
end . result
41
49
end
42
50
43
51
def delay_2_data
44
52
delay_2_semaphore . async do |task |
45
53
@_delay_2_data ||= begin
46
- puts "-> delay_2_data"
47
- data = JSON . parse ( internet . get ( "https://httpbin.org/delay/2" ) . read )
48
- puts "<- delay_2_data"
49
- data
54
+ Console . logger . measure ( self , "delay_2_data" ) do
55
+ JSON . parse ( internet . get ( "https://httpbin.org/delay/2" ) . read )
56
+ end
50
57
end
51
58
end . result
52
59
end
You can’t perform that action at this time.
0 commit comments