futuroscope 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/futuroscope/future.rb +9 -4
- data/lib/futuroscope/version.rb +1 -1
- data/spec/futuroscope/future_spec.rb +8 -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: eae2202922ccb093d05befba1746a250c921550c
|
4
|
+
data.tar.gz: bf6928229dd63743c61b14c42691a12840822f16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a191c018ba8ad53f7340be9549fecbeb4517d561e207ccb67fdd157b5fef8cafdf70859570be714694fa83982a2af391d6a8b0cbbbc1c13dd2d69c93183839a8
|
7
|
+
data.tar.gz: 49da8118b07fa7876908672592cf28554f8d109c2ee6f9ca887d476b8c7bc5d85522974377d15ae2732f39afcf36d75248e16ab1ae39c4e8a6219704107b91cd
|
data/lib/futuroscope/future.rb
CHANGED
@@ -25,15 +25,19 @@ module Futuroscope
|
|
25
25
|
# Returns a Future
|
26
26
|
def initialize(pool = Futuroscope.default_pool, &block)
|
27
27
|
@mutex = Mutex.new
|
28
|
-
@
|
28
|
+
@condition = ConditionVariable.new
|
29
29
|
@pool = pool
|
30
30
|
@block = block
|
31
31
|
@pool.queue self
|
32
32
|
end
|
33
33
|
|
34
34
|
def run_future
|
35
|
-
|
36
|
-
|
35
|
+
begin
|
36
|
+
self.future_value = @block.call
|
37
|
+
rescue Exception => e
|
38
|
+
@exception = e
|
39
|
+
end
|
40
|
+
@condition.signal
|
37
41
|
end
|
38
42
|
|
39
43
|
# Semipublic: Returns the future's value. Will wait for the future to be
|
@@ -43,8 +47,9 @@ module Futuroscope
|
|
43
47
|
def future_value
|
44
48
|
@mutex.synchronize do
|
45
49
|
return @future_value if defined?(@future_value)
|
50
|
+
@condition.wait(@mutex)
|
46
51
|
end
|
47
|
-
@
|
52
|
+
raise @exception if @exception
|
48
53
|
@future_value
|
49
54
|
end
|
50
55
|
|
data/lib/futuroscope/version.rb
CHANGED
@@ -36,5 +36,13 @@ module Futuroscope
|
|
36
36
|
future = Future.new{object}
|
37
37
|
expect(future).to_not be_empty
|
38
38
|
end
|
39
|
+
|
40
|
+
it "captures exceptions and re-raises them when calling the value" do
|
41
|
+
future = Future.new{ raise "Ed Balls" }
|
42
|
+
|
43
|
+
expect(lambda{
|
44
|
+
future.inspect
|
45
|
+
}).to raise_error(Exception)
|
46
|
+
end
|
39
47
|
end
|
40
48
|
end
|