parallelizer 0.0.2-java → 0.0.3-java
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/parallelizer.rb +14 -0
- 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: 3960f5486b3fa034ffa62508d6f5183c24f43cc6
|
4
|
+
data.tar.gz: 7eadc69bdff090b0ac7082cc6bccadc04dc47ff0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46102a617b24a77ff993f33cc20b75e84f1ff54c716e4dbab91629ea19bce84ccf9fb7763d49e2f9d74436edf801767fc60c7feaa5f1b42a4adf7a4c5d087b23
|
7
|
+
data.tar.gz: f79a1e07d0082e96d7f86cc6584698936c74ba78651de0c0496c2a2a161d605080e7424351034ab015a2cf1f870a659276f0f80d272a8544e8f78999e730bbd2
|
data/lib/parallelizer.rb
CHANGED
@@ -18,6 +18,9 @@ java_import 'org.rubygems.parallelizer.DefaultDaemonThreadFactory'
|
|
18
18
|
|
19
19
|
|
20
20
|
class Parallelizer
|
21
|
+
class RejectedExecutionError < RuntimeError
|
22
|
+
end
|
23
|
+
|
21
24
|
attr_accessor :max_acceptable_delay, :delayed_too_long_proc
|
22
25
|
|
23
26
|
def initialize ops={} #:core_pool_threads, :max_pool_threads, :keep_alive_time, :max_acceptable_delay, :delayed_too_long_proc, :prestart_all_core_threads
|
@@ -46,6 +49,10 @@ class Parallelizer
|
|
46
49
|
@pool.shutdown
|
47
50
|
end
|
48
51
|
|
52
|
+
def await_termination(seconds)
|
53
|
+
@pool.await_termination(seconds, TimeUnit::SECONDS)
|
54
|
+
end
|
55
|
+
|
49
56
|
#works like a normal map, but in parallel, and also if an exception is raised that exception
|
50
57
|
#will be stored in that index instead of the result
|
51
58
|
def map enumerator, &proc
|
@@ -99,7 +106,14 @@ class Parallelizer
|
|
99
106
|
|
100
107
|
if i < computation_array.size - 1
|
101
108
|
task = FutureTask.new(comp)
|
109
|
+
|
110
|
+
begin
|
102
111
|
@pool.execute task
|
112
|
+
rescue Java::JavaUtilConcurrent::RejectedExecutionException
|
113
|
+
raise RejectedExecutionException.new($!.message)
|
114
|
+
end
|
115
|
+
|
116
|
+
|
103
117
|
future_tasks << task
|
104
118
|
else #last element, run it in this thread
|
105
119
|
comp.call
|