concurrent_rails 0.1.3 → 0.1.4
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 +4 -4
- data/README.md +8 -8
- data/lib/concurrent_rails/future.rb +1 -2
- data/lib/concurrent_rails/promises.rb +7 -7
- data/lib/concurrent_rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c9f6c5865a512a981fb3be8f87dadffbc2751c0bb8937b4929af57b3fa691a7
|
4
|
+
data.tar.gz: 40e7a30066f9cb04a4093fef697e0e36733d6ca9c7302cbe4b3af4ad7d7e29e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31ba76250826eab804ac7941e6bd33bf9887d367bcf4dcd1b7dca306b3c44287ca1d5c9c75396e7ed8b88168675251ca8df597b4b175c1aa5cee1287fbbb9181
|
7
|
+
data.tar.gz: 3beebfc9b8dc305b555dca571570737247c0409dd67976d0a526d6f37ae64531c2fedafb4de62ef3edb90e867db3ace8131abfa152998b1ff047534c62d7d251
|
data/README.md
CHANGED
@@ -17,26 +17,26 @@ This library provides three classes that will help you run tasks in parallel: `C
|
|
17
17
|
Similar to other classes, all you have to do is call `.future` helper and pass a block:
|
18
18
|
|
19
19
|
```ruby
|
20
|
-
irb(main):001:0> future = ConcurrentRails::Promises.future { sleep(
|
21
|
-
=> #<ConcurrentRails::Promises:
|
20
|
+
irb(main):001:0> future = ConcurrentRails::Promises.future(5) { |v| sleep(v); 42 }
|
21
|
+
=> #<ConcurrentRails::Promises:0x00007fed68db66b0 @future_instance=#<Concurrent::Promises::Future
|
22
22
|
|
23
|
-
irb(main):
|
23
|
+
irb(main):002:0> future.state
|
24
24
|
=> :pending
|
25
25
|
|
26
|
-
# After
|
27
|
-
irb(main):
|
26
|
+
# After the process slept for 5 seconds
|
27
|
+
irb(main):003:0> future.state
|
28
28
|
=> :fulfilled
|
29
29
|
|
30
|
-
irb(main):
|
30
|
+
irb(main):004:0> future.value
|
31
31
|
=> 42
|
32
32
|
```
|
33
33
|
|
34
34
|
The benefit of `Promises` over a pure `Future` class is that you can chain futures without blocking the main thread.
|
35
35
|
|
36
36
|
```ruby
|
37
|
-
irb(main):
|
37
|
+
irb(main):001:0> future = ConcurrentRails::Promises.future { 42 }.then { |v| v * 2 }
|
38
38
|
=> #<ConcurrentRails::Promises:0x00007fe92eba3460 @future_instance=#...
|
39
|
-
irb(main):
|
39
|
+
irb(main):002:0> future.value
|
40
40
|
=> 84
|
41
41
|
```
|
42
42
|
|
@@ -5,7 +5,6 @@ module ConcurrentRails
|
|
5
5
|
extend Forwardable
|
6
6
|
|
7
7
|
def initialize(executor: :io, &block)
|
8
|
-
@task = block
|
9
8
|
@executor = executor
|
10
9
|
@future = run_on_rails(block)
|
11
10
|
end
|
@@ -40,6 +39,6 @@ module ConcurrentRails
|
|
40
39
|
end
|
41
40
|
end
|
42
41
|
|
43
|
-
attr_reader :executor, :
|
42
|
+
attr_reader :executor, :future
|
44
43
|
end
|
45
44
|
end
|
@@ -5,13 +5,13 @@ module ConcurrentRails
|
|
5
5
|
include Concurrent::Promises::FactoryMethods
|
6
6
|
extend Forwardable
|
7
7
|
|
8
|
-
def self.future(*args, &
|
9
|
-
new.run_on_rails(*args, &
|
8
|
+
def self.future(*args, &task)
|
9
|
+
new.run_on_rails(*args, &task)
|
10
10
|
end
|
11
11
|
|
12
|
-
def then(*args, &
|
12
|
+
def then(*args, &task)
|
13
13
|
@future_instance = Rails.application.executor.wrap do
|
14
|
-
future_instance.then(*args, &
|
14
|
+
future_instance.then(*args, &task)
|
15
15
|
end
|
16
16
|
|
17
17
|
self
|
@@ -31,9 +31,9 @@ module ConcurrentRails
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
def run_on_rails(*args, &
|
34
|
+
def run_on_rails(*args, &task)
|
35
35
|
@future_instance = Rails.application.executor.wrap do
|
36
|
-
|
36
|
+
future_on(default_executor, *args, &task)
|
37
37
|
end
|
38
38
|
|
39
39
|
self
|
@@ -43,6 +43,6 @@ module ConcurrentRails
|
|
43
43
|
|
44
44
|
private
|
45
45
|
|
46
|
-
attr_reader :
|
46
|
+
attr_reader :future_instance
|
47
47
|
end
|
48
48
|
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.
|
4
|
+
version: 0.1.4
|
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-04-
|
11
|
+
date: 2021-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|