future-resource 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,2 +1,5 @@
1
+ # 0.0.2
2
+ * Feature: FutureResource#resource now takes an optional argument of the number of seconds to wait before timing out. On timeout, a Timeout::Error will be raised.
3
+
1
4
  # 0.0.1
2
5
  * Initial Release
@@ -1,3 +1,3 @@
1
1
  class FutureResource
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,5 +1,6 @@
1
1
  require "thread"
2
2
  require "monitor"
3
+ require "timeout"
3
4
 
4
5
  class FutureResource
5
6
  def initialize
@@ -11,10 +12,12 @@ class FutureResource
11
12
  !!@resource_lock.synchronize { defined? @resource }
12
13
  end
13
14
 
14
- def resource
15
- @resource_lock.synchronize do
16
- @resource_value_blocker.wait unless defined? @resource
17
- @resource
15
+ def resource(timeout = nil)
16
+ Timeout::timeout timeout do
17
+ @resource_lock.synchronize do
18
+ @resource_value_blocker.wait unless defined? @resource
19
+ @resource
20
+ end
18
21
  end
19
22
  end
20
23
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: future-resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: