latch 0.1.0 → 0.2.0

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{latch}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Kyle Maxwell"]
12
+ s.date = %q{2011-04-30}
13
+ s.description = %q{This is a really simple countdown latch for Ruby.}
14
+ s.email = %q{kyle@kylemaxwell.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "latch.gemspec",
29
+ "lib/latch.rb",
30
+ "spec/latch_spec.rb",
31
+ "spec/spec_helper.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/fizx/latch}
34
+ s.licenses = ["MIT"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.6.2}
37
+ s.summary = %q{This is a really simple countdown latch for Ruby.}
38
+ s.test_files = [
39
+ "spec/latch_spec.rb",
40
+ "spec/spec_helper.rb"
41
+ ]
42
+
43
+ if s.respond_to? :specification_version then
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ s.add_development_dependency(%q<rspec>, ["~> 2.5.0"])
48
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
50
+ s.add_development_dependency(%q<rcov>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<rspec>, ["~> 2.5.0"])
53
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
54
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
55
+ s.add_dependency(%q<rcov>, [">= 0"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<rspec>, ["~> 2.5.0"])
59
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
60
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
61
+ s.add_dependency(%q<rcov>, [">= 0"])
62
+ end
63
+ end
64
+
@@ -1,6 +1,8 @@
1
1
  require "thread"
2
+ require "timeout"
2
3
 
3
4
  class Latch
5
+ class Timeout < ::Timeout::Error; end
4
6
  module Mixin
5
7
  def latch(count = 1, timeout = nil, &block)
6
8
  l = Latch.new(count)
@@ -27,5 +29,6 @@ class Latch
27
29
 
28
30
  def await(timeout = nil)
29
31
  @cv.wait(@mutex, timeout)
32
+ raise Latch::Timeout if @count > 0
30
33
  end
31
34
  end
@@ -27,15 +27,14 @@ describe "Latch" do
27
27
 
28
28
  it "should timeout" do
29
29
  start = Time.now
30
- Latch::Mixin::latch(1, EPSILON) do |l|
31
- Thread.new do
32
- sleep 10
33
- l.decr
30
+ proc {
31
+ Latch::Mixin::latch(1, EPSILON) do |l|
32
+ Thread.new do
33
+ sleep 10
34
+ l.decr
35
+ end
34
36
  end
35
- end
36
- delta = Time.now - start
37
- delta.should > EPSILON
38
- delta.should < 2 * EPSILON
37
+ }.should raise_error(Latch::Timeout)
39
38
  end
40
39
 
41
40
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: latch
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kyle Maxwell
@@ -75,6 +75,7 @@ files:
75
75
  - README
76
76
  - Rakefile
77
77
  - VERSION
78
+ - latch.gemspec
78
79
  - lib/latch.rb
79
80
  - spec/latch_spec.rb
80
81
  - spec/spec_helper.rb
@@ -92,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
93
  requirements:
93
94
  - - ">="
94
95
  - !ruby/object:Gem::Version
95
- hash: 857898899279315681
96
+ hash: -4380555552488188392
96
97
  segments:
97
98
  - 0
98
99
  version: "0"