rdispatch 0.0.1d → 0.0.1e
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/lib/rdispatch.rb +7 -6
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fe4001710114e7b977901bc8e9f7af3570cc4056
|
|
4
|
+
data.tar.gz: 1d407d63364dc5ffcbbea4ded19e4836d1cf34e9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 272e237c26dba840b2f914ff3042466acf23ef9999bd11afd131115c21cfb6d067c285c19771a38a155fdc3da304dc644d50b597ef2f19f31ce59f7789402383
|
|
7
|
+
data.tar.gz: a4850bfb72f12fa715013c36c142b563a63346aadcec3a1bf2ec111630ee662c2c620b018acf5acbfd79ddb90434e82de31a592e58aa5326c3adf03592f9e6d8
|
data/lib/rdispatch.rb
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
class RDispatch
|
|
2
2
|
|
|
3
|
-
tasks = []
|
|
4
3
|
def initialize
|
|
5
|
-
tasks = []
|
|
4
|
+
@tasks = []
|
|
6
5
|
end
|
|
7
6
|
|
|
8
7
|
def create_task(callback, data)
|
|
@@ -13,22 +12,24 @@ class RDispatch
|
|
|
13
12
|
split_data = data.each_slice((data.size/avail_threads.to_f).round).to_a
|
|
14
13
|
split_data.each do |data_array|
|
|
15
14
|
# create tasks, each with 1/n of data, where n is number of cpu cores
|
|
16
|
-
tasks << proc { callback.call(data_array) }
|
|
15
|
+
@tasks << proc { callback.call(data_array) }
|
|
17
16
|
end
|
|
18
17
|
end
|
|
19
18
|
|
|
20
19
|
def run!
|
|
21
20
|
# run tasks, each in its own thread
|
|
22
21
|
threads = []
|
|
23
|
-
tasks.each do |t|
|
|
22
|
+
@tasks.each do |t|
|
|
23
|
+
puts "spawning thread"
|
|
24
24
|
threads << Thread.new do
|
|
25
|
-
puts "spawning thread"
|
|
26
25
|
t.call
|
|
27
26
|
end
|
|
28
27
|
end
|
|
29
28
|
threads.each(&:join)
|
|
30
|
-
tasks = []
|
|
29
|
+
@tasks = []
|
|
31
30
|
end
|
|
32
31
|
|
|
32
|
+
private
|
|
33
|
+
@tasks = []
|
|
33
34
|
end
|
|
34
35
|
require 'rdispatch/sys'
|