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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c35a579ddfa81bd3d51a36dc93a4f774e676949c
4
- data.tar.gz: 39328f8e0892c81da476a3566d9ab7d4194a72fc
3
+ metadata.gz: eae2202922ccb093d05befba1746a250c921550c
4
+ data.tar.gz: bf6928229dd63743c61b14c42691a12840822f16
5
5
  SHA512:
6
- metadata.gz: 5bb7cc63fe178d5442d6b164ff2c54bc6dd4f35f77870852e5e2e327acdec4587c5dc19fb9de3c7ecb715507f9813c91644a6255c7a73b3ab2a58e4a89301031
7
- data.tar.gz: 677d8995bfccb00a705fff0574cc22d50c3ecc1190e856ff9690e3e7aebb467cd022451d2a0f5b4ebd81bc32d2ca5ff95a7772e03219bc2f8fc85c5c4c08a429
6
+ metadata.gz: a191c018ba8ad53f7340be9549fecbeb4517d561e207ccb67fdd157b5fef8cafdf70859570be714694fa83982a2af391d6a8b0cbbbc1c13dd2d69c93183839a8
7
+ data.tar.gz: 49da8118b07fa7876908672592cf28554f8d109c2ee6f9ca887d476b8c7bc5d85522974377d15ae2732f39afcf36d75248e16ab1ae39c4e8a6219704107b91cd
@@ -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
- @queue = Queue.new
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
- self.future_value = @block.call
36
- @queue.push :ok
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
- @queue.pop
52
+ raise @exception if @exception
48
53
  @future_value
49
54
  end
50
55
 
@@ -1,3 +1,3 @@
1
1
  module Futuroscope
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: futuroscope
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep Jaume Rey Peroy