timeouter 0.1.0 → 0.1.1
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/timeouter/timer.rb +9 -10
- data/lib/timeouter/version.rb +1 -1
- data/lib/timeouter.rb +7 -7
- metadata +20 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4eebc16a3cd094d67214eba8d29e32c94b9e3c8c553d063fe6df190dac55f75b
|
4
|
+
data.tar.gz: 9ac2cf769c9345afcf99bda5dbe2f2a5d299d1ac1eaa05bfa43643dffb18df8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1dcb98874efc98cc29cff7a8c3cd04a2746c7e74cbd00f42cc29b638b908bdd57e4e8967858083dcb86b57a09b1cfce67042776f425a66393f7ed4bf07df440
|
7
|
+
data.tar.gz: ccb5256cadaac18f390441fa5a8bee9223b628f77646774300ebc3e251d298978e148b8660f28a9c0a98dbf6ce30863654c511b3f413be17884f0fdc1cdff71c
|
data/lib/timeouter/timer.rb
CHANGED
@@ -3,18 +3,17 @@ require 'timeout'
|
|
3
3
|
module Timeouter
|
4
4
|
class Timer
|
5
5
|
|
6
|
-
attr_reader :
|
6
|
+
attr_reader :timeout, :started_at#, :exhausted_at
|
7
7
|
|
8
|
-
def initialize(timeout = 0, eclass:
|
8
|
+
def initialize(timeout = 0, eclass: nil, message: nil)
|
9
9
|
# ensure only positive timeouts
|
10
10
|
timeout ||= 0
|
11
|
-
timeout = [timeout, 0].max
|
11
|
+
@timeout = [timeout, 0].max
|
12
12
|
|
13
|
-
@eclass = eclass
|
14
|
-
@
|
13
|
+
@eclass = eclass || Timeouter::TimeoutError
|
14
|
+
@message = message || 'execution expired'
|
15
15
|
|
16
16
|
@started_at = Time.now
|
17
|
-
@exhausted_at = timeout > 0 ? @started_at + timeout : nil
|
18
17
|
end
|
19
18
|
|
20
19
|
# elapsed time from creation
|
@@ -24,12 +23,12 @@ module Timeouter
|
|
24
23
|
|
25
24
|
# time left to be exhausted or nil if timeout was 0
|
26
25
|
def left
|
27
|
-
@
|
26
|
+
(@timeout > 0) ? [@timeout - elapsed, 0].max : nil
|
28
27
|
end
|
29
28
|
|
30
29
|
# is timeout exhausted? or nil when timeout was 0
|
31
30
|
def exhausted?
|
32
|
-
@
|
31
|
+
(@timeout > 0) ? elapsed > @timeout : nil
|
33
32
|
end
|
34
33
|
|
35
34
|
# is timeout NOT exhausted? or true when timeout was 0
|
@@ -38,7 +37,7 @@ module Timeouter
|
|
38
37
|
end
|
39
38
|
|
40
39
|
# ensure timeout NOT exhausted raise exception otherwise
|
41
|
-
def running!(eclass = @eclass, message: @
|
40
|
+
def running!(eclass = @eclass, message: @message)
|
42
41
|
!exhausted? || (raise eclass.new(message))
|
43
42
|
end
|
44
43
|
|
@@ -47,7 +46,7 @@ module Timeouter
|
|
47
46
|
yield(self) while self.running?
|
48
47
|
end
|
49
48
|
|
50
|
-
def loop!(eclass = @eclass, message: @
|
49
|
+
def loop!(eclass = @eclass, message: @message)
|
51
50
|
yield(self) while self.running!(eclass, message: message)
|
52
51
|
end
|
53
52
|
|
data/lib/timeouter/version.rb
CHANGED
data/lib/timeouter.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require 'timeouter/timer'
|
2
2
|
|
3
3
|
|
4
4
|
module Timeouter
|
@@ -7,16 +7,16 @@ module Timeouter
|
|
7
7
|
|
8
8
|
class << self
|
9
9
|
|
10
|
-
def run(timeout = 0, eclass: Timeouter::TimeoutError,
|
11
|
-
yield(Timeouter::Timer.new(timeout, eclass: eclass,
|
10
|
+
def run(timeout = 0, eclass: Timeouter::TimeoutError, message: 'execution expired')
|
11
|
+
yield(Timeouter::Timer.new(timeout, eclass: eclass, message: message))
|
12
12
|
end
|
13
13
|
|
14
|
-
def loop(timeout = 0, eclass: Timeouter::TimeoutError,
|
15
|
-
Timeouter::Timer.new(timeout, eclass: eclass,
|
14
|
+
def loop(timeout = 0, eclass: Timeouter::TimeoutError, message: 'execution expired', &block)
|
15
|
+
Timeouter::Timer.new(timeout, eclass: eclass, message: message).loop(&block)
|
16
16
|
end
|
17
17
|
|
18
|
-
def loop!(timeout = 0, eclass: Timeouter::TimeoutError,
|
19
|
-
Timeouter::Timer.new(timeout, eclass: eclass,
|
18
|
+
def loop!(timeout = 0, eclass: Timeouter::TimeoutError, message: 'execution expired', &block)
|
19
|
+
Timeouter::Timer.new(timeout, eclass: eclass, message: message).loop!(&block)
|
20
20
|
end
|
21
21
|
|
22
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timeouter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samoilenko Yuri
|
@@ -59,7 +59,7 @@ dependencies:
|
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '0'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
62
|
+
name: rspec_junit_formatter
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
65
|
- - ">="
|
@@ -73,7 +73,7 @@ dependencies:
|
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
76
|
+
name: simplecov
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
79
|
- - ">="
|
@@ -86,7 +86,21 @@ dependencies:
|
|
86
86
|
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
|
-
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: simplecov-console
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
description: Timeouter is advisory timeout helper without any background threads.
|
90
104
|
email:
|
91
105
|
- kinnalru@gmail.com
|
92
106
|
executables: []
|
@@ -116,9 +130,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
130
|
- !ruby/object:Gem::Version
|
117
131
|
version: '0'
|
118
132
|
requirements: []
|
119
|
-
|
120
|
-
rubygems_version: 2.7.9
|
133
|
+
rubygems_version: 3.0.3
|
121
134
|
signing_key:
|
122
135
|
specification_version: 4
|
123
|
-
summary: Timeouter is advisory timeout helper
|
136
|
+
summary: Timeouter is advisory timeout helper without any background threads.
|
124
137
|
test_files: []
|