concurrent_rails 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a745bd40255c338ca8e305b8d6477d91f6a249db984e613042df56f42af674b0
4
- data.tar.gz: 7e141fc895855f868f0b1d34537ab27155c75ab8db3b833a237ca86ac889448e
3
+ metadata.gz: cb04be405f37c5acf9a5fa5ed21ba327bb92168cc6f830dc52314356ccbfd4dd
4
+ data.tar.gz: cabf17aba3c7c80939b95d5af80e48cb6fcc8c4260f2278386e3952b2128a59f
5
5
  SHA512:
6
- metadata.gz: 8467ca3bd91d7393e163c85ac820d182a29df3cc5d8f52baf71fccb563c0a009fd54d125f5fa98598b9c051565479381e09b88e823f20f5c5dff8b909526e62d
7
- data.tar.gz: 95b7ca4107bd52b51a769adb93b56ed1c54bf1bee8d797fc8db71524afec128b092a85505c2a0953c1458a21b551d0434ccfba591797385a148ed44c3cde33cd
6
+ metadata.gz: 971b987e34b8eb5142d05f774368cec64e363c4c7ecd23555dcd594b8631d4237c85ab969a5392c184ed7a727c78c13586876e1ce6b629ae86bf865ac1ccec1d
7
+ data.tar.gz: 575157aae6f247f68672327689b7396804d63e1b78162f68a73be51ac56a818039bb40c8af765c5481dbf2b557fb4cee884d93aaf5949ea744ba9599aeb99479
data/README.md CHANGED
@@ -127,7 +127,7 @@ For more information on how Futures works and how Rails handles multithread chec
127
127
  Add this line to your application's Gemfile:
128
128
 
129
129
  ```ruby
130
- gem 'concurrent_rails', '~> 0.5.1'
130
+ gem 'concurrent_rails', '~> 0.7'
131
131
  ```
132
132
 
133
133
  And then execute:
@@ -146,6 +146,24 @@ gem install concurrent_rails
146
146
 
147
147
  Pull requests are always welcome
148
148
 
149
+
150
+ ## Updating Ruby or Rails versions using Appraisal
151
+
152
+ This gem uses Appraisal for multiple Ruby and Rails versions testing. To update the Ruby or Rails versions, you can run:
153
+
154
+ ```bash
155
+ bundle exec appraisal install
156
+ ```
157
+
158
+ and to run the tests for all versions, you can run:
159
+
160
+ ```bash
161
+ bundle exec appraisal rake test
162
+ ```
163
+
164
+ Check the [usage](https://github.com/thoughtbot/appraisal?tab=readme-ov-file#usage) section of the Appraisal gem for more information on how to use it.
165
+
166
+
149
167
  ## License
150
168
 
151
169
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConcurrentRails
4
+ module CombinatorAdapter
5
+ extend ActiveSupport::Concern
6
+
7
+ class_methods do
8
+ def zip(*promises)
9
+ new(:io).tap { |p| p.instance_variable_set(:@instance, Concurrent::Promises.zip(*unwrap(promises))) }
10
+ end
11
+
12
+ def any_resolved_future(*promises)
13
+ new(:io).tap { |p| p.instance_variable_set(:@instance, Concurrent::Promises.any_resolved_future(*unwrap(promises))) }
14
+ end
15
+
16
+ def fulfilled_future(value, executor = :io)
17
+ new(executor).tap { |p| p.instance_variable_set(:@instance, Concurrent::Promises.fulfilled_future(value)) }
18
+ end
19
+
20
+ def rejected_future(reason, executor = :io)
21
+ new(executor).tap { |p| p.instance_variable_set(:@instance, Concurrent::Promises.rejected_future(reason)) }
22
+ end
23
+
24
+ private
25
+
26
+ def unwrap(promises)
27
+ promises.map { |p| p.is_a?(ConcurrentRails::Promises) ? p.__send__(:instance) : p }
28
+ end
29
+ end
30
+ end
31
+ end
@@ -14,8 +14,9 @@ module ConcurrentRails
14
14
  end
15
15
  end
16
16
 
17
- def delay_on_rails(*args, &task)
18
- @instance = rails_wrapped { delay_on(executor, *args, &task) }
17
+ def delay_on_rails(*args)
18
+ wrapped_task = proc { |*a| rails_wrapped { yield(*a) } }
19
+ @instance = delay_on(executor, *args, &wrapped_task)
19
20
 
20
21
  self
21
22
  end
@@ -14,8 +14,9 @@ module ConcurrentRails
14
14
  end
15
15
  end
16
16
 
17
- def future_on_rails(*args, &task)
18
- @instance = rails_wrapped { future_on(executor, *args, &task) }
17
+ def future_on_rails(*args)
18
+ wrapped_task = proc { |*a| rails_wrapped { yield(*a) } }
19
+ @instance = future_on(executor, *args, &wrapped_task)
19
20
 
20
21
  self
21
22
  end
@@ -3,8 +3,10 @@
3
3
  module ConcurrentRails
4
4
  class Promises
5
5
  include Concurrent::Promises::FactoryMethods
6
+ include ConcurrentRails::CombinatorAdapter
6
7
  include ConcurrentRails::DelayAdapter
7
8
  include ConcurrentRails::FutureAdapter
9
+ include ConcurrentRails::ScheduleAdapter
8
10
 
9
11
  def initialize(executor)
10
12
  @executor = executor
@@ -12,18 +14,15 @@ module ConcurrentRails
12
14
 
13
15
  %i[value value!].each do |method_name|
14
16
  define_method(method_name) do |timeout = nil, timeout_value = nil|
15
- permit_concurrent_loads do
16
- instance.public_send(method_name, timeout, timeout_value)
17
- end
17
+ rails_wrapped { instance.public_send(method_name, timeout, timeout_value) }
18
18
  end
19
19
  end
20
20
 
21
21
  %i[then chain].each do |chainable|
22
22
  define_method(chainable) do |*args, &task|
23
23
  method = "#{chainable}_on"
24
- @instance = rails_wrapped do
25
- instance.public_send(method, executor, *args, &task)
26
- end
24
+ wrapped_task = proc { |*a| rails_wrapped { task.call(*a) } }
25
+ @instance = instance.public_send(method, executor, *args, &wrapped_task)
27
26
 
28
27
  self
29
28
  end
@@ -36,24 +35,22 @@ module ConcurrentRails
36
35
  end
37
36
 
38
37
  def wait(timeout = nil)
39
- result = permit_concurrent_loads { instance.__send__(:wait_until_resolved, timeout) }
38
+ result = rails_wrapped { instance.__send__(:wait_until_resolved, timeout) }
40
39
 
41
40
  timeout ? result : self
42
41
  end
43
42
 
44
43
  %i[on_fulfillment on_rejection on_resolution].each do |method|
45
44
  define_method(method) do |*args, &callback_task|
46
- rails_wrapped do
47
- @instance = instance.__send__(:"#{method}_using", executor, *args, &callback_task)
48
- end
45
+ wrapped_callback = proc { |*a| rails_wrapped { callback_task.call(*a) } }
46
+ @instance = instance.__send__(:"#{method}_using", executor, *args, &wrapped_callback)
49
47
 
50
48
  self
51
49
  end
52
50
 
53
51
  define_method(:"#{method}!") do |*args, &callback_task|
54
- rails_wrapped do
55
- @instance = instance.__send__(:add_callback, "callback_#{method}", args, callback_task)
56
- end
52
+ wrapped_callback = proc { |*a| rails_wrapped { callback_task.call(*a) } }
53
+ @instance = instance.__send__(:add_callback, "callback_#{method}", args, wrapped_callback)
57
54
 
58
55
  self
59
56
  end
@@ -69,12 +66,6 @@ module ConcurrentRails
69
66
  Rails.application.executor.wrap(&)
70
67
  end
71
68
 
72
- def permit_concurrent_loads(&block)
73
- rails_wrapped do
74
- ActiveSupport::Dependencies.interlock.permit_concurrent_loads(&block)
75
- end
76
- end
77
-
78
69
  attr_reader :instance
79
70
  end
80
71
  end
@@ -2,5 +2,8 @@
2
2
 
3
3
  module ConcurrentRails
4
4
  class Railtie < ::Rails::Railtie
5
+ initializer "concurrent_rails.executor_hooks" do |app|
6
+ # TODO: Add something here at some point
7
+ end
5
8
  end
6
9
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConcurrentRails
4
+ module ScheduleAdapter
5
+ extend ActiveSupport::Concern
6
+
7
+ class_methods do
8
+ def schedule(delay, *args, &task)
9
+ schedule_on(:io, delay, *args, &task)
10
+ end
11
+
12
+ def schedule_on(executor, delay, *args, &task)
13
+ new(executor).schedule_on_rails(delay, *args, &task)
14
+ end
15
+ end
16
+
17
+ def schedule_on_rails(delay, *args)
18
+ wrapped_task = proc { |*a| rails_wrapped { yield(*a) } }
19
+ @instance = schedule_on(executor, delay, *args, &wrapped_task)
20
+
21
+ self
22
+ end
23
+ end
24
+ end
@@ -9,7 +9,7 @@ module ConcurrentRails
9
9
  define_method(test_mode) do |&task|
10
10
  @execution_mode = test_mode
11
11
  result = task.call
12
- @execution_mode = :real
12
+ @execution_mode = "real"
13
13
 
14
14
  result
15
15
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ConcurrentRails
4
- VERSION = "0.7.0"
4
+ VERSION = "0.8.0"
5
5
  end
@@ -5,5 +5,4 @@ require "zeitwerk"
5
5
  loader = Zeitwerk::Loader.for_gem
6
6
  loader.setup
7
7
 
8
- module ConcurrentRails
9
- end
8
+ module ConcurrentRails; end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: concurrent_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luiz Eduardo Kowalski
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-11-30 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: railties
@@ -16,14 +15,14 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '7.0'
18
+ version: '7.2'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
- version: '7.0'
25
+ version: '7.2'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: zeitwerk
29
28
  requirement: !ruby/object:Gem::Requirement
@@ -49,18 +48,22 @@ files:
49
48
  - README.md
50
49
  - Rakefile
51
50
  - lib/concurrent_rails.rb
51
+ - lib/concurrent_rails/combinator_adapter.rb
52
52
  - lib/concurrent_rails/delay_adapter.rb
53
53
  - lib/concurrent_rails/future_adapter.rb
54
54
  - lib/concurrent_rails/promises.rb
55
55
  - lib/concurrent_rails/railtie.rb
56
+ - lib/concurrent_rails/schedule_adapter.rb
56
57
  - lib/concurrent_rails/testing.rb
57
58
  - lib/concurrent_rails/version.rb
58
59
  homepage: https://github.com/luizkowalski/concurrent_rails
59
60
  licenses:
60
61
  - MIT
61
62
  metadata:
63
+ homepage_uri: https://github.com/luizkowalski/concurrent_rails
64
+ source_code_uri: https://github.com/luizkowalski/concurrent_rails
65
+ changelog_uri: https://github.com/luizkowalski/concurrent_rails/blob/master/CHANGELOG.md
62
66
  rubygems_mfa_required: 'true'
63
- post_install_message:
64
67
  rdoc_options: []
65
68
  require_paths:
66
69
  - lib
@@ -68,15 +71,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
68
71
  requirements:
69
72
  - - ">="
70
73
  - !ruby/object:Gem::Version
71
- version: '3.1'
74
+ version: '3.2'
72
75
  required_rubygems_version: !ruby/object:Gem::Requirement
73
76
  requirements:
74
77
  - - ">="
75
78
  - !ruby/object:Gem::Version
76
79
  version: '0'
77
80
  requirements: []
78
- rubygems_version: 3.5.23
79
- signing_key:
81
+ rubygems_version: 4.0.8
80
82
  specification_version: 4
81
83
  summary: Multithread is hard
82
84
  test_files: []