maybe_later 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97eeed3e9c54c6fc50761b564b2931efb9095256dd204713202f661fd3bae530
4
- data.tar.gz: c970f7ce158383f37d37e889b2e7eebc6709fb99a2c62fb70aab7f7ea8f6894f
3
+ metadata.gz: d8f9b846afbd0afe731fb08fd0d8bb7803bbe35641e346a203ec3d7dbdec5469
4
+ data.tar.gz: 9e524137408d44ed6c8aa9ac42530988cc1effd900b30b6cb5d4105bab2aabc8
5
5
  SHA512:
6
- metadata.gz: d85dd59825388991863f20945f8ee5b1ee8f9ce133657c0910b0e5adffd61eee9eebb185d33f714f1cb33bf9c04bd70eb02be68ae059fba3ef31480244e3c183
7
- data.tar.gz: ee4340c11eb2f7da34ea743947ca6f9649a3bf2e44923dd371990e7efc3c092e6dcc84943eb498080bad88f830f26a66c5b84de796f217c458056c1c88c1a9fa
6
+ metadata.gz: f44f66474c11bde93b9708a2357aa353abd7d10ea395af1da2494cabb6b5e364b2b9234ff3a3dbb0e386935c5486e92a2ebfc03046fac2d7053f73669c535f2f
7
+ data.tar.gz: 8d643450ef22440c17d881c20be5620e9029318d5ce979217a0b6f1bf41483dc0ee36b1406d8add4ebdca21742dbce037c246d8ec8a7a46b6dd44b0210a25e50
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.0.2] - 2022-01-20
2
+
3
+ - Only close HTTP connections when there are >0 inline tasks to be run
4
+
1
5
  ## [0.0.1] - 2022-01-19
2
6
 
3
7
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- maybe_later (0.0.1)
4
+ maybe_later (0.0.2)
5
5
  concurrent-ruby (~> 1.1.9)
6
6
  railties (>= 6.0.0)
7
7
 
data/README.md CHANGED
@@ -50,7 +50,7 @@ MaybeLater.run {
50
50
  ```
51
51
 
52
52
  Each block passed to `MaybeLater.run` will be run after the HTTP response is
53
- sent and the response will include a `"Connection: close` header.
53
+ sent.
54
54
 
55
55
  If the code you're calling needs to be executed in the same thread that's
56
56
  handling the HTTP request, you can pass `inline: true`:
@@ -61,9 +61,15 @@ MaybeLater.run(inline: true) {
61
61
  }
62
62
  ```
63
63
 
64
- And your code will be run right after the HTTP response is sent (note: this can
65
- potentially saturate the server's available threads and effectively block
66
- subsequent HTTP requests!)
64
+ And your code will be run right after the HTTP response is sent. Additionally,
65
+ if there are any inline tasks to be run, the response will include a
66
+ `"Connection: close` header so that the browser doesn't sit waiting on its
67
+ connection while the web thread executes the deferred code.
68
+
69
+ _[**Warning about `inline`:** running
70
+ slow inline tasks runs the risk of saturating the server's available threads
71
+ listening for connections, effectively shifting the slowness of one request onto
72
+ later ones!]_
67
73
 
68
74
 
69
75
  ## Configuration
@@ -72,7 +78,7 @@ The gem offers a few configuration options:
72
78
 
73
79
  ```ruby
74
80
  MaybeLater.config do |config|
75
- # Will be called if a `MaybeLater.run {}` callback errors, e.g.:
81
+ # Will be called if a block passed to MaybeLater.run raises an error
76
82
  config.on_error = ->(error) {
77
83
  # e.g. Honeybadger.notify(error)
78
84
  }
@@ -92,7 +98,7 @@ end
92
98
  ## Help! Why isn't my code running?
93
99
 
94
100
  If the blocks you pass to `MaybeLater.run` aren't running, possible
95
- explanations:
101
+ explanations include:
96
102
 
97
103
  * Because the blocks passed to `MaybeLater.run` are themselves stored in a
98
104
  thread-local array, if you invoke `MaybeLater.run` from a thread that isn't
@@ -8,12 +8,14 @@ module MaybeLater
8
8
 
9
9
  def call(env)
10
10
  status, headers, body = @app.call(env)
11
- if Store.instance.any_callbacks?
11
+ if Store.instance.callbacks.any?
12
12
  env[RACK_AFTER_REPLY] ||= []
13
13
  env[RACK_AFTER_REPLY] << -> {
14
14
  RunsCallbacks.new.call
15
15
  }
16
- headers["Connection"] = "close"
16
+ if Store.instance.callbacks.any? { |cb| cb.inline }
17
+ headers["Connection"] = "close"
18
+ end
17
19
  end
18
20
  [status, headers, body]
19
21
  end
@@ -9,10 +9,6 @@ module MaybeLater
9
9
  @callbacks = []
10
10
  end
11
11
 
12
- def any_callbacks?
13
- !@callbacks.empty?
14
- end
15
-
16
12
  def add_callback(callable)
17
13
  @callbacks << callable
18
14
  end
@@ -1,3 +1,3 @@
1
1
  module MaybeLater
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maybe_later
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Searls