request_store-fibers 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +29 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +68 -0
- data/LICENSE.txt +21 -0
- data/README.md +72 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/request_store/fibers/version.rb +7 -0
- data/lib/request_store/fibers.rb +33 -0
- data/request_store-fibers.gemspec +35 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0f27de487e2f37ab305e62051b8eab1b67a84a548ebdd21ec8c721c7259beb5a
|
4
|
+
data.tar.gz: a237fc77b22a751c4aef0462a24369a4a9119350b8d824bfcf7dca6021a432e4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3c4193e0d24109159afe13b3d27bc040445dce9aa281808cfcab56e114af1edc10393a0ea76eff5bbba8995ce6244d2f7929baefc4fae20d98f6941ee68e6eb4
|
7
|
+
data.tar.gz: 9c45b86a5d2b5400e0f2516652899506f9644f1bb346a55f2284bab84c6231619d2ec5683a86b7a8cafd38f050fb4fc07aa179d5eb7ee126f40c1a185ee96c84
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.5
|
3
|
+
NewCops: enable
|
4
|
+
|
5
|
+
Metrics/MethodLength:
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
Style/GuardClause:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Style/Lambda:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Style/NegatedIf:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Style/StringLiterals:
|
18
|
+
Enabled: true
|
19
|
+
EnforcedStyle: double_quotes
|
20
|
+
|
21
|
+
Style/StringLiteralsInInterpolation:
|
22
|
+
Enabled: true
|
23
|
+
EnforcedStyle: double_quotes
|
24
|
+
|
25
|
+
Layout/LineLength:
|
26
|
+
Max: 100
|
27
|
+
|
28
|
+
Metrics/BlockLength:
|
29
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
request_store-fibers (0.1.0)
|
5
|
+
fiber_hook
|
6
|
+
request_store
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.4.2)
|
12
|
+
diff-lcs (1.4.4)
|
13
|
+
fiber_hook (0.1.0)
|
14
|
+
parallel (1.21.0)
|
15
|
+
parser (3.0.2.0)
|
16
|
+
ast (~> 2.4.1)
|
17
|
+
rack (2.2.3)
|
18
|
+
rainbow (3.0.0)
|
19
|
+
rake (13.0.6)
|
20
|
+
regexp_parser (2.1.1)
|
21
|
+
request_store (1.5.0)
|
22
|
+
rack (>= 1.4)
|
23
|
+
rexml (3.2.5)
|
24
|
+
rspec (3.10.0)
|
25
|
+
rspec-core (~> 3.10.0)
|
26
|
+
rspec-expectations (~> 3.10.0)
|
27
|
+
rspec-mocks (~> 3.10.0)
|
28
|
+
rspec-core (3.10.1)
|
29
|
+
rspec-support (~> 3.10.0)
|
30
|
+
rspec-expectations (3.10.1)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.10.0)
|
33
|
+
rspec-mocks (3.10.2)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.10.0)
|
36
|
+
rspec-support (3.10.3)
|
37
|
+
rubocop (1.23.0)
|
38
|
+
parallel (~> 1.10)
|
39
|
+
parser (>= 3.0.0.0)
|
40
|
+
rainbow (>= 2.2.2, < 4.0)
|
41
|
+
regexp_parser (>= 1.8, < 3.0)
|
42
|
+
rexml
|
43
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
44
|
+
ruby-progressbar (~> 1.7)
|
45
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
46
|
+
rubocop-ast (1.13.0)
|
47
|
+
parser (>= 3.0.1.1)
|
48
|
+
rubocop-rake (0.6.0)
|
49
|
+
rubocop (~> 1.0)
|
50
|
+
rubocop-rspec (2.6.0)
|
51
|
+
rubocop (~> 1.19)
|
52
|
+
ruby-progressbar (1.11.0)
|
53
|
+
unicode-display_width (2.1.0)
|
54
|
+
|
55
|
+
PLATFORMS
|
56
|
+
arm64-darwin-21
|
57
|
+
x86_64-linux
|
58
|
+
|
59
|
+
DEPENDENCIES
|
60
|
+
rake (~> 13.0)
|
61
|
+
request_store-fibers!
|
62
|
+
rspec (~> 3.0)
|
63
|
+
rubocop (~> 1.21)
|
64
|
+
rubocop-rake
|
65
|
+
rubocop-rspec
|
66
|
+
|
67
|
+
BUNDLED WITH
|
68
|
+
2.2.31
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Brian Morearty
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# RequestStore::Fibers
|
2
|
+
|
3
|
+
Ya know how sometimes you need to keep track of per-request state in a Rails app?
|
4
|
+
You reach for [RequestStore](https://github.com/steveklabnik/request_store)
|
5
|
+
to do that, right? Works great.
|
6
|
+
|
7
|
+
## The problem
|
8
|
+
|
9
|
+
But now you want to start using the [Async](https://github.com/socketry/async)
|
10
|
+
gem with the [Falcon](https://github.com/socketry/falcon) server for
|
11
|
+
asynchronous I/O and improved performance and scalability.
|
12
|
+
Problem is, those gems work by creating fibers—and the thread-local storage that
|
13
|
+
RequestStore uses is also fiber-local, so
|
14
|
+
it doesn’t get passed down into child fibers. You could be in the middle
|
15
|
+
of handling a request, start a new fiber to fire off an async I/O request to
|
16
|
+
a service, and that fiber no longer has access to the per-request store.
|
17
|
+
|
18
|
+
## The solution
|
19
|
+
|
20
|
+
Any time a fiber is created, this gem copies the
|
21
|
+
`RequestStore` data into the new fiber’s thread-local storage.
|
22
|
+
|
23
|
+
## But how?
|
24
|
+
|
25
|
+
Ruby! It’s magical! You can hook into anything, including standard library calls.
|
26
|
+
I hook into `Fiber.new` and store `Thread.current[:request_store]` in a
|
27
|
+
variable. Once the newly-created fiber resumes for the first time, I copy that value
|
28
|
+
into the fiber’s `Thread.current[:request_store]`.
|
29
|
+
|
30
|
+
## Installation
|
31
|
+
|
32
|
+
Add this line to your application's Gemfile:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
gem 'request_store-fibers'
|
36
|
+
```
|
37
|
+
|
38
|
+
And then execute:
|
39
|
+
|
40
|
+
$ bundle install
|
41
|
+
|
42
|
+
Or install it yourself as:
|
43
|
+
|
44
|
+
$ gem install request_store-fibers
|
45
|
+
|
46
|
+
## Usage
|
47
|
+
|
48
|
+
Make an initializer that does this:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
RequestStore::Fibers.init
|
52
|
+
```
|
53
|
+
|
54
|
+
If you ever need to unhook fiber creation, here’s how:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
RequestStore::Fibers.uninit
|
58
|
+
```
|
59
|
+
|
60
|
+
## Development
|
61
|
+
|
62
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
63
|
+
|
64
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
65
|
+
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/BMorearty/request_store-fibers.
|
69
|
+
|
70
|
+
## License
|
71
|
+
|
72
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "request_store/fibers"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "request_store"
|
4
|
+
require "fiber_hook"
|
5
|
+
require_relative "fibers/version"
|
6
|
+
|
7
|
+
module RequestStore
|
8
|
+
# Make RequestStore work with fibers.
|
9
|
+
module Fibers
|
10
|
+
class Error < StandardError; end
|
11
|
+
|
12
|
+
def self.init
|
13
|
+
@hook_id = Fiber.hook(
|
14
|
+
new: -> { [RequestStore.store, RequestStore.active?] },
|
15
|
+
resume: ->(value) {
|
16
|
+
RequestStore.store = value[0]
|
17
|
+
if value[1]
|
18
|
+
RequestStore.begin!
|
19
|
+
else
|
20
|
+
RequestStore.end!
|
21
|
+
end
|
22
|
+
}
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.uninit
|
27
|
+
raise Error, "You must init before you can uninit" unless @hook_id
|
28
|
+
|
29
|
+
Fiber.unhook(@hook_id)
|
30
|
+
@hook_id = nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/request_store/fibers/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "request_store-fibers"
|
7
|
+
spec.version = RequestStore::Fibers::VERSION
|
8
|
+
spec.authors = ["Brian Morearty"]
|
9
|
+
spec.email = ["brian@morearty.org"]
|
10
|
+
|
11
|
+
spec.summary = "Lets you use RequestStore with a fiber-based server."
|
12
|
+
spec.description = "Lets you use RequestStore with a fiber-based server by passing " \
|
13
|
+
"RequestStore’s thread-local variables to child fibers as they are created."
|
14
|
+
spec.homepage = "https://github.com/BMorearty/request_store-fibers"
|
15
|
+
spec.license = "MIT"
|
16
|
+
spec.required_ruby_version = ">= 2.5.0"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
20
|
+
spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
|
21
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
(f == __FILE__) ||
|
28
|
+
f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
29
|
+
end
|
30
|
+
end
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_dependency "fiber_hook"
|
34
|
+
spec.add_dependency "request_store"
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: request_store-fibers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Morearty
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-11-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fiber_hook
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: request_store
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Lets you use RequestStore with a fiber-based server by passing RequestStore’s
|
42
|
+
thread-local variables to child fibers as they are created.
|
43
|
+
email:
|
44
|
+
- brian@morearty.org
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".rspec"
|
50
|
+
- ".rubocop.yml"
|
51
|
+
- CHANGELOG.md
|
52
|
+
- Gemfile
|
53
|
+
- Gemfile.lock
|
54
|
+
- LICENSE.txt
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- bin/console
|
58
|
+
- bin/setup
|
59
|
+
- lib/request_store/fibers.rb
|
60
|
+
- lib/request_store/fibers/version.rb
|
61
|
+
- request_store-fibers.gemspec
|
62
|
+
homepage: https://github.com/BMorearty/request_store-fibers
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata:
|
66
|
+
homepage_uri: https://github.com/BMorearty/request_store-fibers
|
67
|
+
source_code_uri: https://github.com/BMorearty/request_store-fibers
|
68
|
+
changelog_uri: https://github.com/BMorearty/request_store-fibers/blob/main/CHANGELOG.md
|
69
|
+
rubygems_mfa_required: 'true'
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 2.5.0
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubygems_version: 3.2.31
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Lets you use RequestStore with a fiber-based server.
|
89
|
+
test_files: []
|