futuroscope 0.0.9 → 0.0.10
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/futuroscope/future.rb +10 -12
- data/lib/futuroscope/version.rb +1 -1
- 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: 60ea73929c330082898296c2512037998d2b9ad3
|
4
|
+
data.tar.gz: 8886af488ab4d89dedac2e96488bd89f3e5bfd3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdcd4ef68d0fd26892f76e7f0f6ea0ac451569beac1eff44d697205f82837d5b642a25c4b26fbdea4fbc6565fb181d5bf32966e206482559c3623f8346868b9c
|
7
|
+
data.tar.gz: dda945e88fc5f37816ab99a8882cc042c24c92e709e613a7b51957d8341e14a9fca65cc43a18ab278cc3c4765ceedf48386e192d5bfae7d4cf7e87142a83772f
|
data/lib/futuroscope/future.rb
CHANGED
@@ -24,21 +24,19 @@ module Futuroscope
|
|
24
24
|
# Returns a Future
|
25
25
|
def initialize(pool = Futuroscope.default_pool, &block)
|
26
26
|
@mutex = Mutex.new
|
27
|
-
@
|
27
|
+
@queue = Queue.new
|
28
28
|
@pool = pool
|
29
29
|
@block = block
|
30
30
|
@pool.queue self
|
31
31
|
end
|
32
32
|
|
33
33
|
def run_future
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
@exception = e
|
39
|
-
end
|
40
|
-
@condition.signal
|
34
|
+
begin
|
35
|
+
@future_value = @block.call
|
36
|
+
rescue Exception => e
|
37
|
+
@exception = e
|
41
38
|
end
|
39
|
+
@queue.push :ok
|
42
40
|
end
|
43
41
|
|
44
42
|
# Semipublic: Returns the future's value. Will wait for the future to be
|
@@ -47,11 +45,11 @@ module Futuroscope
|
|
47
45
|
# Returns the Future's block execution result.
|
48
46
|
def future_value
|
49
47
|
@mutex.synchronize do
|
50
|
-
|
51
|
-
|
48
|
+
begin
|
49
|
+
raise @exception if @exception
|
50
|
+
return @future_value if defined?(@future_value)
|
51
|
+
end while @queue.pop
|
52
52
|
end
|
53
|
-
raise @exception if @exception
|
54
|
-
@future_value
|
55
53
|
end
|
56
54
|
|
57
55
|
def_delegators :future_value,
|
data/lib/futuroscope/version.rb
CHANGED