batches 1.0.1 → 1.0.2
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 +5 -5
- data/README.md +8 -3
- data/lib/batches.rb +6 -9
- data/lib/batches/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4af89b1db30d354712b15e647bfa67d1f431e7d0068aa5722f38a36504b3a0bd
|
4
|
+
data.tar.gz: d47f9a6cb369edd1d44c6d97518c1b2b2ae464871ee3c1571c4dc26053b9a11a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6acdbe923ebbd9aff2f9bcd868d93991c738d9e13c118e441287ffbc12242f53f8e3a45ebcbd2f3d78cdd84b810f3f74ec9615f44969d4df845ae25f3f880492
|
7
|
+
data.tar.gz: d15daf9c08e90e8488d25e831eb554bf993860846a994ec5f16d435d44b79f51def74e88ee0ea0da88f7dbc6794e71f992b9aa0238e00540bb041301f17e5fb8
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Batches
|
2
2
|
|
3
|
-
|
3
|
+
A simple wrapper of multithreading in Ruby
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,11 +18,16 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
Handling the entity array in 20 threads
|
22
|
+
|
23
|
+
require 'batches'
|
24
|
+
Batches.do(20, entities) do |entity|
|
25
|
+
do_some_thing_with(entity)
|
26
|
+
end
|
22
27
|
|
23
28
|
## Contributing
|
24
29
|
|
25
|
-
1. Fork it ( https://github.com/
|
30
|
+
1. Fork it ( https://github.com/Slacken/batches/fork )
|
26
31
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
32
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
33
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/batches.rb
CHANGED
@@ -4,15 +4,12 @@ class Batches
|
|
4
4
|
class NoBlockError < ArgumentError; end
|
5
5
|
|
6
6
|
def self.do(cocurrence, entities, &block)
|
7
|
-
raise NoBlockError, "No block given"
|
8
|
-
entities.each_slice(cocurrence) do |group|
|
9
|
-
threads =
|
10
|
-
|
11
|
-
threads << Thread.new(entity) do |ent|
|
12
|
-
block.call(ent)
|
13
|
-
end
|
7
|
+
raise NoBlockError, "No block given" if block.nil?
|
8
|
+
entities.each_slice(cocurrence).map do |group|
|
9
|
+
threads = group.map do |entity|
|
10
|
+
Thread.new(entity){|e| block.call(e) }
|
14
11
|
end
|
15
|
-
threads.
|
16
|
-
end
|
12
|
+
threads.map{|t| t.value }
|
13
|
+
end.flatten(1)
|
17
14
|
end
|
18
15
|
end
|
data/lib/batches/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: batches
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- binz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
version: '0'
|
75
75
|
requirements: []
|
76
76
|
rubyforge_project:
|
77
|
-
rubygems_version: 2.
|
77
|
+
rubygems_version: 2.6.14
|
78
78
|
signing_key:
|
79
79
|
specification_version: 4
|
80
80
|
summary: A simple wrapper of <cocurrence> threads to process <entities>
|