smart_polling 0.0.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +1 -3
- data/CHANGELOG.md +16 -0
- data/README.md +1 -1
- data/lib/smart_polling.rb +3 -3
- data/lib/smart_polling/version.rb +1 -1
- data/spec/smart_polling_spec.rb +4 -4
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15a233d2c98ca46c95e4554a0d1c57e3220d8e3e
|
4
|
+
data.tar.gz: 06811073887522d2b729aebe2e8fcf42a75dd890
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9aa74881fe2720d02f0fd5e35da30211abbe693d18b62c81943a05750085f6854e8c485d27eb7feb47c6c69d916a19bee13bac60bf9246bc1d959cf3d2831a8
|
7
|
+
data.tar.gz: df63e3134a505f60841d2724845daa7a76d001f294f2bf67ff0787ec7c925f70245d242dfe6cb4ce9a89fc015e3420168ebaa9d8a5e4333f775fbbdb7bd11924
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.3.0
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Smart Polling ChangeLog
|
2
|
+
|
3
|
+
## 1.0.0
|
4
|
+
|
5
|
+
* **Breaking change:** Rename `seconds` parameter to `timeout`
|
6
|
+
* **Breaking change:** Rename `delay` parameter to `interval`
|
7
|
+
* Add CHANGELOG file
|
8
|
+
|
9
|
+
## 0.0.2
|
10
|
+
|
11
|
+
* Better package description
|
12
|
+
* Add README
|
13
|
+
|
14
|
+
## 0.0.1
|
15
|
+
|
16
|
+
* Initial Version
|
data/README.md
CHANGED
@@ -25,7 +25,7 @@ Or install it yourself as:
|
|
25
25
|
It will call the external service until the response is "done":
|
26
26
|
|
27
27
|
```ruby
|
28
|
-
SmartPolling.poll(
|
28
|
+
SmartPolling.poll(timeout: 60, interval: 5) do
|
29
29
|
response = ExternalService.call
|
30
30
|
response == "done"
|
31
31
|
end
|
data/lib/smart_polling.rb
CHANGED
@@ -3,14 +3,14 @@ require "smart_polling/version"
|
|
3
3
|
class SmartPolling
|
4
4
|
class TimeoutError < StandardError; end
|
5
5
|
|
6
|
-
def self.poll(
|
6
|
+
def self.poll(timeout: 10, interval: 1, timeout_error: nil)
|
7
7
|
timeout_error ||= TimeoutError.new
|
8
|
-
time_limit = Time.now +
|
8
|
+
time_limit = Time.now + timeout
|
9
9
|
|
10
10
|
while Time.now < time_limit do
|
11
11
|
result = yield
|
12
12
|
return result if result
|
13
|
-
sleep
|
13
|
+
sleep interval
|
14
14
|
end
|
15
15
|
|
16
16
|
raise timeout_error
|
data/spec/smart_polling_spec.rb
CHANGED
@@ -6,12 +6,12 @@ RSpec.describe SmartPolling do
|
|
6
6
|
let(:block) { -> { false } }
|
7
7
|
|
8
8
|
it "raises SmartPolling::TimeoutError" do
|
9
|
-
expect { SmartPolling.poll(
|
9
|
+
expect { SmartPolling.poll(timeout: 0.2, interval: 0.05, &block) }.
|
10
10
|
to raise_error(SmartPolling::TimeoutError)
|
11
11
|
end
|
12
12
|
|
13
13
|
it "raises a custom error" do
|
14
|
-
expect { SmartPolling.poll(
|
14
|
+
expect { SmartPolling.poll(timeout: 0.2, interval: 0.05, timeout_error: StandardError.new("custom_error"), &block) }.
|
15
15
|
to raise_error(StandardError, "custom_error")
|
16
16
|
end
|
17
17
|
end
|
@@ -23,7 +23,7 @@ RSpec.describe SmartPolling do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "returns the first non-false value" do
|
26
|
-
expect(SmartPolling.poll(
|
26
|
+
expect(SmartPolling.poll(timeout: 0.2, interval: 0.05, &block)).to eq("return_value")
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -31,7 +31,7 @@ RSpec.describe SmartPolling do
|
|
31
31
|
let(:block) { -> { "return_value" } }
|
32
32
|
|
33
33
|
it "returns the value" do
|
34
|
-
expect(SmartPolling.poll(
|
34
|
+
expect(SmartPolling.poll(timeout: 0.2, interval: 0.05, &block)).to eq("return_value")
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_polling
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mateus Del Bianco
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- ".ruby-gemset"
|
66
66
|
- ".ruby-version"
|
67
67
|
- ".travis.yml"
|
68
|
+
- CHANGELOG.md
|
68
69
|
- Gemfile
|
69
70
|
- LICENSE.txt
|
70
71
|
- README.md
|
@@ -94,11 +95,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
95
|
version: '0'
|
95
96
|
requirements: []
|
96
97
|
rubyforge_project:
|
97
|
-
rubygems_version: 2.
|
98
|
+
rubygems_version: 2.5.1
|
98
99
|
signing_key:
|
99
100
|
specification_version: 4
|
100
101
|
summary: SmartPolling is the smartest way to poll something.
|
101
102
|
test_files:
|
102
103
|
- spec/smart_polling_spec.rb
|
103
104
|
- spec/spec_helper.rb
|
104
|
-
has_rdoc:
|