futuroscope 0.1.7 → 0.1.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: 03cdb1ddd7c212ef63c625d610754a92386a1c73
4
- data.tar.gz: 90f54b489a3176aa6ad82c17195cb7d8e429d687
3
+ metadata.gz: 4fd5d28ef251a17a7ef93724aeb9bd633c7918e5
4
+ data.tar.gz: b99fa961184a443c7fcc68c3e547536bfa8295c6
5
5
  SHA512:
6
- metadata.gz: a7cf8ff237e9610854c1dd2ab2aabb24143ce632cdf376900e68685811ba72075532c8eb0d06e685992de2ac1a5bc1da556774f9b1ce4db6a7e0e62c5fda752f
7
- data.tar.gz: 7dd1ea1d9c1dda894349798a74da9b9b3f05a73774c2a135b213b762662f8ac0ef9fd6d6723eac02c77c3b7ada1082601930a203c83a3fa6c0fa05f120d22f4e
6
+ metadata.gz: 216febe1e1ef8ea9041cbdb053dd2d5aa926e12a30056bff728e48947931436e59160c9d1ca50bec0cafc0a4579f9e804b8887cba6270d324c0ac595370691ae
7
+ data.tar.gz: 702c1d669a4b74cc126aacac0cbf3841651737588b8c6068ae6f12d1aa01536698933856c80825ae33112881824e75fa923846c84b973c9b905710064bd885be
data/.travis.yml CHANGED
@@ -3,6 +3,6 @@ cache: bundler
3
3
  rvm:
4
4
  - 1.9.3
5
5
  - 2.0.0
6
- - rbx
6
+ - rbx-2.2.3
7
7
  - 2.1.0
8
8
  - jruby-19mode
data/README.md CHANGED
@@ -6,10 +6,14 @@
6
6
  [![Dependency Status](https://gemnasium.com/codegram/futuroscope.png)](https://gemnasium.com/codegram/futuroscope)
7
7
 
8
8
  Futursocope is a simple library that implements futures in ruby. Futures are a
9
- concurrency pattern meant to help you deal with concurrency in a simple way.
9
+ concurrency pattern meant to help you deal with threads in a simple, transparent way.
10
10
 
11
- It's specially useful when working in Service Oriented Architectures where HTTP
12
- calls can take a long time and you only expect a value from them.
11
+ It's specially useful in situations where you have calls to an expensive resource that
12
+ could be done in parallel (they are not chained), but you don't wanna deal with low-level
13
+ threads. HTTP calls are a good example.
14
+
15
+ Also useful when you want to spin up a process that runs in the background, do some stuff
16
+ in the middle, and wait for that process to return.
13
17
 
14
18
  [![The awesome Futuroscope park](http://europe.eurostar.com/wp-content/uploads/2011/06/Futuroscope10-59-of-107.jpg)](http://futuroscope.com)
15
19
 
@@ -24,7 +28,7 @@ method on in it will be forwarded to the block's return value.
24
28
  If the thread didn't finish yet, it will block the program's execution until
25
29
  it's finished. Otherwise, it will immediately return its value.
26
30
 
27
- Futuroscope is tested on `MRI 1.9.3`, `MRI 2.0.0`, `MRI 2.1.0`, `Rubinius (1.9)` and `JRuby (1.9)`.
31
+ Futuroscope is tested on `MRI 1.9.3`, `MRI 2.0.0`, `MRI 2.1.0`, `Rubinius (2.2.3)` and `JRuby (1.9)`.
28
32
 
29
33
  Check out [futuroscope's post on Codegram's blog](http://blog.codegram.com/2013/5/new-gem-released-futuroscope) to get started.
30
34
 
@@ -30,6 +30,7 @@ module Futuroscope
30
30
  @queue = ::SizedQueue.new(1)
31
31
  @pool = pool
32
32
  @block = block
33
+ @mutex = Mutex.new
33
34
  @pool.queue self
34
35
  end
35
36
 
@@ -70,7 +71,9 @@ module Futuroscope
70
71
  private
71
72
 
72
73
  def resolved_future_value
73
- @resolved_future ||= @queue.pop
74
+ @resolved_future || @mutex.synchronize do
75
+ @resolved_future ||= @queue.pop
76
+ end
74
77
  end
75
78
  end
76
79
  end
@@ -1,3 +1,3 @@
1
1
  module Futuroscope
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -66,5 +66,32 @@ module Futuroscope
66
66
  expect(future.dup).to eq future
67
67
  end
68
68
 
69
+ context "when at least another thread is alive" do
70
+ # If no threads are alive, the VM raises an exception, therefore we need to ensure there is one.
71
+
72
+ before :each do
73
+ @live_thread = Thread.new { loop { } }
74
+ end
75
+
76
+
77
+ it "doesn't hang when 2 threads try to obtain its result before it's finished" do
78
+ test_thread = Thread.new do
79
+ future = Future.new { sleep 1; 1 }
80
+ f1 = Future.new { future + 1 }
81
+ f2 = Future.new { future + 2 }
82
+ f1.future_value
83
+ f2.future_value
84
+ end
85
+ sleep 2
86
+ expect(test_thread).to_not be_alive
87
+ test_thread.kill
88
+ end
89
+
90
+
91
+ after :each do
92
+ @live_thread.kill
93
+ end
94
+
95
+ end
69
96
  end
70
97
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: futuroscope
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep Jaume Rey Peroy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-29 00:00:00.000000000 Z
11
+ date: 2014-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler