concurrent_rails 0.1.7 → 0.1.8

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: fe2277deed1f15f3c47a332667db0b85bbfb0d39d58bcb6539fa0d15d843c55d
4
- data.tar.gz: 0e347f69da65b60fcbdb63a04cdcb3bac782ba01b6e543db93428ff4c2bdbdc0
3
+ metadata.gz: 257bcdcbd99076d7b73c193297ce5bc410c1fd5962bb823b965b5abbdf21197c
4
+ data.tar.gz: 5ae2230ba4416193fac70bcd9500673e7d96081491786717eb8d6ce95c938f92
5
5
  SHA512:
6
- metadata.gz: '079c165494e1eea8ae9c98fe89031c87408808527a3f90eda3c5c5d87598bfb5932b0285acaa99d4e5e714a1012af3676bc16fc9b5929268ff26640b90f4b191'
7
- data.tar.gz: 97944d3f3db134d08eb894f6f3211a705cb080ec4d4ec331657c94940fd08a08c4f1f46859d430f3c2e5097a1cc54d7de322e9f39a0fcc48de78d49982cd26e8
6
+ metadata.gz: df4405c6f8e8efe155dea24db8a3799955b59c4d3a93118153b557711941c66428027caea64d245df4437be49d3d0482ffb2461bad863b38877e152f57eb6970
7
+ data.tar.gz: 8c11ffcd0afbeedf533a8da19ca19f79a1e2566e326946f55e699337f45c179a2f245f5b4fd46f62b694a9803ac317cf0bfb6dec95c38285cf3487c5631a4457
data/README.md CHANGED
@@ -143,7 +143,7 @@ For more information on how Futures work and how Rails handle multithread check
143
143
  Add this line to your application's Gemfile:
144
144
 
145
145
  ```ruby
146
- gem 'concurrent_rails', '~> 0.1.7'
146
+ gem 'concurrent_rails', '~> 0.1.8'
147
147
  ```
148
148
 
149
149
  And then execute:
@@ -17,7 +17,7 @@ module ConcurrentRails
17
17
 
18
18
  %i[value value!].each do |method_name|
19
19
  define_method method_name do
20
- Rails.application.executor.wrap do
20
+ rails_wrapped do
21
21
  ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
22
22
  future.__send__(method_name)
23
23
  end
@@ -30,13 +30,17 @@ module ConcurrentRails
30
30
  private
31
31
 
32
32
  def run_on_rails(block)
33
- @future = Rails.application.executor.wrap do
33
+ @future = rails_wrapped do
34
34
  Concurrent::Future.new(executor: executor) do
35
- Rails.application.executor.wrap(&block)
35
+ rails_wrapped(&block)
36
36
  end
37
37
  end
38
38
  end
39
39
 
40
+ def rails_wrapped(&block)
41
+ Rails.application.executor.wrap(&block)
42
+ end
43
+
40
44
  attr_reader :executor, :future
41
45
  end
42
46
  end
@@ -11,29 +11,34 @@ module ConcurrentRails
11
11
  end
12
12
 
13
13
  def future_on(executor, *args, &task)
14
- new.with_rails(executor, *args, &task)
14
+ new(executor).run_on_rails(*args, &task)
15
15
  end
16
16
  end
17
17
 
18
- def then(*args, &task)
19
- @future_instance = Rails.application.executor.wrap do
20
- future_instance.then(*args, &task)
21
- end
18
+ def initialize(executor)
19
+ @executor = executor
20
+ end
21
+
22
+ def run_on_rails(*args, &task)
23
+ @future_instance = rails_wrapped { future_on(executor, *args, &task) }
22
24
 
23
25
  self
24
26
  end
25
27
 
26
- def chain(*args, &task)
27
- Rails.application.executor.wrap do
28
- future_instance.chain(*args, &task)
29
- end
28
+ %i[then chain].each do |chainable|
29
+ define_method(chainable) do |*args, &task|
30
+ method = "#{chainable}_on"
31
+ @future_instance = rails_wrapped do
32
+ future_instance.__send__(method, executor, *args, &task)
33
+ end
30
34
 
31
- self
35
+ self
36
+ end
32
37
  end
33
38
 
34
39
  %i[value value!].each do |method_name|
35
- define_method method_name do |timeout = nil, timeout_value = nil|
36
- Rails.application.executor.wrap do
40
+ define_method(method_name) do |timeout = nil, timeout_value = nil|
41
+ rails_wrapped do
37
42
  ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
38
43
  future_instance.__send__(method_name, timeout, timeout_value)
39
44
  end
@@ -41,18 +46,16 @@ module ConcurrentRails
41
46
  end
42
47
  end
43
48
 
44
- def with_rails(executor, *args, &task)
45
- @future_instance = Rails.application.executor.wrap do
46
- future_on(executor, *args, &task)
47
- end
48
-
49
- self
49
+ %i[state reason rejected? resolved? fulfilled?].each do |delegatable|
50
+ def_delegator :@future_instance, delegatable
50
51
  end
51
52
 
52
- def_delegators :@future_instance, :state, :reason, :rejected?, :resolved?
53
-
54
53
  private
55
54
 
56
- attr_reader :future_instance
55
+ def rails_wrapped(&block)
56
+ Rails.application.executor.wrap(&block)
57
+ end
58
+
59
+ attr_reader :future_instance, :executor
57
60
  end
58
61
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ConcurrentRails
4
- VERSION = '0.1.7'
4
+ VERSION = '0.1.8'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: concurrent_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luiz Eduardo Kowalski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-04 00:00:00.000000000 Z
11
+ date: 2021-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -68,7 +68,6 @@ files:
68
68
  - lib/concurrent_rails/promises.rb
69
69
  - lib/concurrent_rails/railtie.rb
70
70
  - lib/concurrent_rails/version.rb
71
- - lib/tasks/concurrent_rails_tasks.rake
72
71
  homepage: https://github.com/luizkowalski/concurrent_rails
73
72
  licenses:
74
73
  - MIT
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
- # desc "Explaining what the task does"
3
- # task :concurrent_rails do
4
- # # Task goes here
5
- # end