thread 0.0.6.1 → 0.0.6.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 +4 -4
- data/lib/thread/future.rb +11 -8
- data/lib/thread/pool.rb +6 -1
- data/thread.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c934f1f9fc550daf4578bd312a80851a7ea76074
|
4
|
+
data.tar.gz: 2d678d694a58381d2f197b902341f213c1b887cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d33610502d9bfc7630b03265743c9fcb5459d115553512b36f41e7d800077a08c96fc79de451c9a5a4f58cca47b7d17a70720e2f7a3d77b201a4eb8ccb9953b
|
7
|
+
data.tar.gz: 555dee244c8984b1d8e5ee58f68bebeb12784872eb40b3a48fe6ea6dcaa42b75206dc19baf93967a13dcd2b738de717a32987a8c2bcee9b43686ff682404cb3a
|
data/lib/thread/future.rb
CHANGED
@@ -16,12 +16,13 @@ require 'thread'
|
|
16
16
|
class Thread::Future
|
17
17
|
Cancel = Class.new(Exception)
|
18
18
|
|
19
|
-
# Create a future with the passed block.
|
20
|
-
def initialize (&block)
|
19
|
+
# Create a future with the passed block and optionally using the passed pool.
|
20
|
+
def initialize (pool = nil, &block)
|
21
21
|
raise ArgumentError, 'no block given' unless block
|
22
22
|
|
23
|
-
@mutex
|
24
|
-
|
23
|
+
@mutex = Mutex.new
|
24
|
+
|
25
|
+
task = proc {
|
25
26
|
begin
|
26
27
|
deliver block.call
|
27
28
|
rescue Exception => e
|
@@ -30,6 +31,8 @@ class Thread::Future
|
|
30
31
|
deliver nil
|
31
32
|
end
|
32
33
|
}
|
34
|
+
|
35
|
+
@thread = pool ? pool.process(&task) : Thread.new(&task)
|
33
36
|
end
|
34
37
|
|
35
38
|
# Check if an exception has been raised.
|
@@ -131,14 +134,14 @@ end
|
|
131
134
|
|
132
135
|
class Thread
|
133
136
|
# Helper to create a future
|
134
|
-
def self.future (&block)
|
135
|
-
Thread::Future.new(&block)
|
137
|
+
def self.future (pool = nil, &block)
|
138
|
+
Thread::Future.new(pool, &block)
|
136
139
|
end
|
137
140
|
end
|
138
141
|
|
139
142
|
module Kernel
|
140
143
|
# Helper to create a future.
|
141
|
-
def future (&block)
|
142
|
-
Thread::Future.new(&block)
|
144
|
+
def future (pool = nil, &block)
|
145
|
+
Thread::Future.new(pool, &block)
|
143
146
|
end
|
144
147
|
end
|
data/lib/thread/pool.rb
CHANGED
@@ -69,6 +69,11 @@ class Thread::Pool
|
|
69
69
|
@thread = nil
|
70
70
|
end
|
71
71
|
|
72
|
+
# Raise an exception in the thread used by the task.
|
73
|
+
def raise (exception)
|
74
|
+
@thread.raise(exception)
|
75
|
+
end
|
76
|
+
|
72
77
|
# Terminate the exception with an optionally given exception.
|
73
78
|
def terminate! (exception = Asked)
|
74
79
|
return if terminated? || finished? || timeout?
|
@@ -77,7 +82,7 @@ class Thread::Pool
|
|
77
82
|
|
78
83
|
return unless running?
|
79
84
|
|
80
|
-
|
85
|
+
self.raise exception
|
81
86
|
end
|
82
87
|
|
83
88
|
# Force the task to timeout.
|
data/thread.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thread
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.6.
|
4
|
+
version: 0.0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- meh.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|