async_io 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/async_io/base.rb +18 -0
- data/lib/async_io/load.rb +1 -1
- data/lib/async_io/version.rb +1 -1
- data/spec/async_io/base_spec.rb +17 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 642dfbfa59b37724c55c6822ad7daccd25f0e3ca
|
4
|
+
data.tar.gz: 066e65d115549847bb9d7c4fd05d0a42c862a516
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42648eb1cadf0d3cc98988296d965087c228916dad3d670a9b954390c129664f0778339e457733e5f96266cba23bc4d76931b2362776da7dafdcf25a648f58fa
|
7
|
+
data.tar.gz: 52ca496f501cca01702cda4233acd00b7396901df52a5270e60f849e857d52215cd176ddc26a02a60ed8b2c95537dddaae48327c6f9c499d34e4b4bc90349265
|
data/lib/async_io/base.rb
CHANGED
@@ -93,5 +93,23 @@ module AsyncIO
|
|
93
93
|
worker(payload) { }
|
94
94
|
end
|
95
95
|
|
96
|
+
def interval(seconds)
|
97
|
+
new_interval? do
|
98
|
+
while true
|
99
|
+
rescuer { yield }
|
100
|
+
sleep(seconds)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def new_interval?
|
106
|
+
@interval ||= Thread.new { yield }
|
107
|
+
end
|
108
|
+
|
109
|
+
def clear_interval!
|
110
|
+
@interval.terminate
|
111
|
+
@interval = nil
|
112
|
+
end
|
113
|
+
|
96
114
|
end
|
97
115
|
end
|
data/lib/async_io/load.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require 'async_io/
|
1
|
+
require 'async_io/base'
|
data/lib/async_io/version.rb
CHANGED
data/spec/async_io/base_spec.rb
CHANGED
@@ -18,7 +18,8 @@ end
|
|
18
18
|
|
19
19
|
describe AsyncIO::Base do
|
20
20
|
|
21
|
-
|
21
|
+
let(:fake_thread) { double("FakeThread") }
|
22
|
+
before { Thread.stub(:new).and_return(fake_thread) }
|
22
23
|
let(:alien) { AsyncIO::Base.new }
|
23
24
|
let(:logger) { AsyncIO::Logger }
|
24
25
|
|
@@ -88,8 +89,7 @@ describe AsyncIO::Base do
|
|
88
89
|
payload = -> { :im_an_async_job }
|
89
90
|
|
90
91
|
worker = double
|
91
|
-
alien.stub(:worker).
|
92
|
-
and_return(worker)
|
92
|
+
alien.stub(:worker).and_return(worker)
|
93
93
|
|
94
94
|
##
|
95
95
|
# See the link below for a better understading how to
|
@@ -102,6 +102,20 @@ describe AsyncIO::Base do
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
+
context "#interval" do
|
106
|
+
it "executes a job in a given interval" do
|
107
|
+
alien.should_receive(:new_interval?)
|
108
|
+
alien.interval(0.0001) { sleep(10) }
|
109
|
+
end
|
110
|
+
|
111
|
+
it "must stop an interval" do
|
112
|
+
fake_thread.should_receive(:terminate)
|
113
|
+
alien.interval(0.0001) { sleep(20) }
|
114
|
+
alien.clear_interval!
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
105
119
|
context "#consumer" do
|
106
120
|
it { alien.should respond_to :consumer }
|
107
121
|
|