holdon 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +15 -0
  2. data/lib/holdon.rb +38 -0
  3. metadata +44 -0
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ODg0Y2ExNThiYjg5ODdjZjk0MmNjNTZhYTMyNDZlMTZmM2MzM2ViMQ==
5
+ data.tar.gz: !binary |-
6
+ MDM3Zjc1YzhlZWQyZTEwMDJkZTNjMjRiYTVhMDI3Zjc4Yzg5MDM2Zg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NGIzNTg5ZDQ1YWYxOGI2ZDkwODM0YjI1ZWE3NjlkZGY0N2FmOGRkNDlmNmQ5
10
+ YjU3MjJhNzRjNzhiZjZmZDM4ZjU4NDM5MzJkNDQ5OGQ5MjM0MDEwZjQxOThl
11
+ MzRkMjZjNWExODIzZTIzNDc2ZDgyZjA4ZjU2ODI1MTdmOWNmMTg=
12
+ data.tar.gz: !binary |-
13
+ YzE3YWM1MTcwNDZiYTg0NDRjZTUyMzJlYWUwYTRiY2IyMzdhZjUxMDFkNmNm
14
+ MjRlZGI3YmMzNTVkMmRhYmZlZWI0ODZiNTc5ZDBjMDc0NWM0MzIxZTM2ZjAz
15
+ NDVmY2Y0MGNkYjNjNzMxMzViMzQxZWRhMmQ3YjNjMWZiYzhjNDI=
@@ -0,0 +1,38 @@
1
+
2
+ module HoldOn
3
+
4
+ class Timeout < Exception
5
+ end
6
+
7
+
8
+ def self.until(options = {}, &block)
9
+ self.breaker(options) do
10
+ result = yield
11
+ break result if result
12
+ end
13
+ end
14
+
15
+
16
+
17
+ def self.breaker(options = {})
18
+ timeout = options.fetch(:timeout, 30)
19
+ interval = options.fetch(:interval, 1)
20
+
21
+ start = Time.now
22
+ loop do
23
+ yield
24
+
25
+ # If the time remaining is less than the interval,
26
+ # then we'll only sleep for the time remaining.
27
+ inv = [interval, (timeout - (Time.now - start))].min
28
+ if inv > 0
29
+ sleep inv
30
+ else
31
+ raise Timeout
32
+ end
33
+
34
+ end
35
+ end
36
+
37
+ end
38
+
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: holdon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian Lauber
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: HoldOn until a condition is true
14
+ email: constructible.truth@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/holdon.rb
20
+ homepage:
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.1.10
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: HoldOn until a condition is true
44
+ test_files: []