waiting 0.1.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.
- checksums.yaml +15 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +11 -0
- data/Gemfile +3 -0
- data/README.md +38 -0
- data/Rakefile +6 -0
- data/lib/waiting/version.rb +3 -0
- data/lib/waiting/waiter.rb +19 -0
- data/lib/waiting.rb +49 -0
- data/waiting.gemspec +24 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OWMxMjlhMjFmOTgyMmZmN2E3ZDA4YTRlNTkxYWEyZWQ1OTcyNzQzMg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OTMxMmY3MmZiOTZjZDc3MjJhY2EyOTRmYWVjYTkxMzc4MzQ1MTU5Nw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZDdkNDhiZjQ3MzBmY2ViZjIzN2Y3MjM0NWJmYWVjNGZkY2ZiZTg0Mzg0Y2Y4
|
10
|
+
ZWE5YzAyMjk4NjJlM2EzZDg1NzBkNzMxZTM3ZjY2YzY4YTEyMzBiNzIwNjQz
|
11
|
+
NjhlZWU2NTk5NmExYzBiZGNmMTY3Y2QzNzBjY2FhOWI5ZTA3Yjc=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MGVlMzIxM2RhYmVmZDg2OGM0NzMxNjA0ZGJkNThjM2ZlNjQzYTI1ZTA1ZDU2
|
14
|
+
ZTY5MDE1YjE2OTlmM2RmMjJmNzMyOGVhY2Q3N2Q4MTVkMzIwNDg2Y2NhMGU5
|
15
|
+
MDIzYTYzYTAwMGMwMDM2ZmFhY2UxMzI2NTVhOThlMmViYjEwOTM=
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.2.3
|
4
|
+
before_install: gem install bundler -v 1.11.2
|
5
|
+
deploy:
|
6
|
+
provider: rubygems
|
7
|
+
api_key:
|
8
|
+
secure: "E7JKnSuA9OzcktaOBczmkUS0h4gcgsWPIGpjJmJDfznJdPiV+YTktqBSFvKhi2fYFMFP6ly7IfQsoj44yn9lPyV1jD7AoURKtMKud/yJZ1T4NFKK68S9ZT9Uu0E7AARohdacWBytwqD4BaOHSka38HzPb27iPfWuuDoqK71KFPuBOO12/kx7O+XLxwdgAMd/ZZwwDy+ctriQgI/8qJNXV+vfrPghFDIrY/E/sWqHxcBPRGhyWggzrkKwy13x770hNVvmHpglJrUW002kmEAXcohvTTaKE0zsiJcG6EBjTLOsVvwoIf/SCF2gRTCeWmsVx4Go7IIkc2RhjtQxDbS+LnT0EcmIBX0ffTg8OPFW4AJPIbpoZPEu8TIvk4htznwbPl46ZJbe33SKtRFBvR7c4SH3lTOk/q/LVKB48KNQFKwdHu7UCeevqe5ON05RIaOAX44UGqTeRQKw4dgwRTMLcpS9O/sQt9tWAC2X/y9MjGpgFuAOiT7VJLnTSE9/gyBwq56l3P4yLRDHoiNvEA1jNFKdsydFbKoL0+s1hiCyDnnmmjjRnErXLNf7H0S9QIV3zSKAc1Qosk9+FoiG4Zh78a+HVBLp/SdyKaAFrrqE46y/Wv6DagcHAhEQ4RbiOJBzHmgdzArz4YHlIBiQRxCPvIJ25gxb4Q+uvMml/DpuxBY="
|
9
|
+
gem: waiting
|
10
|
+
on:
|
11
|
+
repo: meringu/waiting
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Waiting
|
2
|
+
|
3
|
+
Waits so you don't have too!
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'waiting'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install waiting
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'waiting'
|
25
|
+
|
26
|
+
# optional
|
27
|
+
Waiting.default_max_attempts = max_attempts # defaults to 60
|
28
|
+
Waiting.default_interval = interval # seconds, defaults to 5
|
29
|
+
|
30
|
+
# will poll every interval max_attempts times until something returns true
|
31
|
+
Waiting.wait do |waiter|
|
32
|
+
waiter.done if something
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/meringu/waiting.
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Waiting
|
2
|
+
class Waiter
|
3
|
+
# Waiter is in waiting state to start with
|
4
|
+
def initialize
|
5
|
+
@done = false
|
6
|
+
end
|
7
|
+
|
8
|
+
# Mark the waiter as done
|
9
|
+
def done
|
10
|
+
@done = true
|
11
|
+
end
|
12
|
+
|
13
|
+
# Is the waiter done?
|
14
|
+
# @return [Boolean] if the waiter is done
|
15
|
+
def done?
|
16
|
+
@done
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/waiting.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'waiting/waiter'
|
2
|
+
require 'waiting/version'
|
3
|
+
|
4
|
+
module Waiting
|
5
|
+
# get the default wait interval
|
6
|
+
# @return [Fixnum] the interval in seconds
|
7
|
+
def self.default_interval
|
8
|
+
@@default_interval ||= 5
|
9
|
+
end
|
10
|
+
|
11
|
+
# set the default wait interval
|
12
|
+
# @param [Fixnum] interval the interval in seconds
|
13
|
+
def self.default_interval=(interval)
|
14
|
+
@@default_interval = interval
|
15
|
+
end
|
16
|
+
|
17
|
+
# get the default max attempts
|
18
|
+
# @return [Fixnum] the default max attempts
|
19
|
+
def self.default_max_attempts
|
20
|
+
@@default_max_attempts ||= 60
|
21
|
+
end
|
22
|
+
|
23
|
+
# set the default max attempts
|
24
|
+
# @param [Fixnum] max_attempts the default max attempts
|
25
|
+
def self.default_max_attempts=(max_attempts)
|
26
|
+
@@default_max_attempts = max_attempts
|
27
|
+
end
|
28
|
+
|
29
|
+
# wait for something, call #ok on the waiter to signal the wait is over
|
30
|
+
# @param [Hash] opts the options to wait with.
|
31
|
+
# @option opts [Fixnum] :interval polling interval in seconds for checking
|
32
|
+
# @option opts [Fixnum] :max_attempts number of attempts before failing
|
33
|
+
def self.wait(opts = {})
|
34
|
+
interval = opts.fetch(:interval) { default_interval }
|
35
|
+
max_attempts = opts.fetch(:max_attempts) { default_max_attempts }
|
36
|
+
|
37
|
+
waiter = Waiter.new
|
38
|
+
|
39
|
+
attempts = 0
|
40
|
+
|
41
|
+
loop do
|
42
|
+
fail "Timed out after #{interval * max_attempts}s" if attempts >= max_attempts
|
43
|
+
yield(waiter)
|
44
|
+
break if waiter.done?
|
45
|
+
sleep interval
|
46
|
+
attempts += 1
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/waiting.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'waiting/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'waiting'
|
8
|
+
spec.version = Waiting::VERSION
|
9
|
+
spec.authors = ['Henry Muru Paenga']
|
10
|
+
spec.email = ['henry.murupaenga@xero.com']
|
11
|
+
|
12
|
+
spec.summary = "Waits so you don't have too!"
|
13
|
+
spec.description = "Waits so you don't have too!"
|
14
|
+
spec.homepage = 'https://github.com/meringu/waiting'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: waiting
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Henry Muru Paenga
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Waits so you don't have too!
|
56
|
+
email:
|
57
|
+
- henry.murupaenga@xero.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .rspec
|
64
|
+
- .travis.yml
|
65
|
+
- Gemfile
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/waiting.rb
|
69
|
+
- lib/waiting/version.rb
|
70
|
+
- lib/waiting/waiter.rb
|
71
|
+
- waiting.gemspec
|
72
|
+
homepage: https://github.com/meringu/waiting
|
73
|
+
licenses: []
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.4.5
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Waits so you don't have too!
|
95
|
+
test_files: []
|