itimer 4 → 5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/itimer.rb +11 -1
  3. data/test/itimer.rb +37 -0
  4. metadata +7 -11
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0927c46f3b34be6e9ceada8e734dfba266d0a8bd
4
+ data.tar.gz: 31c702637cbfb192eea372550f3031f7776ab21b
5
+ SHA512:
6
+ metadata.gz: 09a998ea7e59e6b62a96f07a01080afdae3ff826e18a0449664f08fe0a7560dd338964dae254881b15f38c5d50e406db24c82d6d6d0e7ce9974f4e2dbef3e6dd
7
+ data.tar.gz: 4b3cffe76bb62e01823f95b66b20ce0e90e66480c524646be720164f2a42c99b00357446b1ecdcdb609e9a1cddb0d320a2c3b69a926d8b452c7686a5b562ab1d
@@ -9,11 +9,21 @@ module Itimer
9
9
  raise klass
10
10
  end
11
11
 
12
+ prev = get(:real)
13
+ start = Time.now
14
+ if prev > 0
15
+ seconds = [prev, seconds].min
16
+ end
17
+
12
18
  begin
13
19
  set(:real, seconds)
14
20
  ret = yield
15
21
  ensure
16
- set(:real, 0)
22
+ if prev > 0
23
+ set(:real, [prev - (Time.now-start), 0].max)
24
+ else
25
+ set(:real, 0)
26
+ end
17
27
  end
18
28
 
19
29
  return ret
@@ -81,6 +81,43 @@ class ItimerTest < Test::Unit::TestCase
81
81
  Itimer.timeout(0.25, RuntimeError) { sleep 5 }
82
82
  end
83
83
  assert_in_delta( Time.now-start, 0.25, 0.1 )
84
+
85
+ # nesting
86
+ start = Time.now
87
+ assert_raise( Itimer::Timeout ) do
88
+ Itimer.timeout(0.25) do
89
+ Itimer.timeout(0.5) do
90
+ sleep 6
91
+ end
92
+ end
93
+ end
94
+
95
+ start = Time.now
96
+ assert_raise( RuntimeError ) do
97
+ Itimer.timeout(0.25) do
98
+ Itimer.timeout(0.1, RuntimeError) do
99
+ sleep 1
100
+ end
101
+ end
102
+ end
103
+ assert_in_delta( Time.now-start, 0.1, 0.1 )
104
+
105
+ start = Time.now
106
+ timeouts = false
107
+ assert_raise( Itimer::Timeout ) do
108
+ Itimer.timeout(0.25) do
109
+ begin
110
+ Itimer.timeout(0.1) do
111
+ sleep 1
112
+ end
113
+ rescue Itimer::Timeout
114
+ timeouts = true
115
+ end
116
+ sleep 1
117
+ end
118
+ end
119
+ assert( timeouts )
120
+ assert_in_delta( Time.now-start, 0.25, 0.1 )
84
121
  end
85
122
 
86
123
  def test_compat
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itimer
3
3
  version: !ruby/object:Gem::Version
4
- version: '4'
5
- prerelease:
4
+ version: '5'
6
5
  platform: ruby
7
6
  authors:
8
7
  - Nate Mueller
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-08-10 00:00:00.000000000 Z
11
+ date: 2013-10-27 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake-compiler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -45,26 +42,25 @@ files:
45
42
  - ext/itimer_native.c
46
43
  homepage: http://github.com/nearbuy/ruby-itimer
47
44
  licenses: []
45
+ metadata: {}
48
46
  post_install_message:
49
47
  rdoc_options: []
50
48
  require_paths:
51
49
  - lib
52
50
  required_ruby_version: !ruby/object:Gem::Requirement
53
- none: false
54
51
  requirements:
55
- - - ! '>='
52
+ - - '>='
56
53
  - !ruby/object:Gem::Version
57
54
  version: 1.9.2
58
55
  required_rubygems_version: !ruby/object:Gem::Requirement
59
- none: false
60
56
  requirements:
61
- - - ! '>='
57
+ - - '>='
62
58
  - !ruby/object:Gem::Version
63
59
  version: '0'
64
60
  requirements: []
65
61
  rubyforge_project:
66
- rubygems_version: 1.8.24
62
+ rubygems_version: 2.0.3
67
63
  signing_key:
68
- specification_version: 3
64
+ specification_version: 4
69
65
  summary: Timeout replacement using POSIX interval timers
70
66
  test_files: []