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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6987084439444f8b65360b694efe1367a3abda31
4
- data.tar.gz: 875b9b38b82ed030e711d84790029f1d0034bbc5
3
+ metadata.gz: 642dfbfa59b37724c55c6822ad7daccd25f0e3ca
4
+ data.tar.gz: 066e65d115549847bb9d7c4fd05d0a42c862a516
5
5
  SHA512:
6
- metadata.gz: 994b5606932c7a7e2b9c5d3052f1468a9a08a85448ab009801a00da31b7d8c09328747f95af1ef5d4d4624345bf0434a8caa27d9c3336ace26825e4b2d30c8d1
7
- data.tar.gz: 24629df537bf4b3f7313a2fbb5340a3577d4733b24394cb42ac854407f532d13708f6c14a1dc12843ca744d8c0a60d03b178d2d89e8d10ccfda2fca1adcbcdba
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/async_io'
1
+ require 'async_io/base'
@@ -1,3 +1,3 @@
1
1
  module AsyncIo
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -18,7 +18,8 @@ end
18
18
 
19
19
  describe AsyncIO::Base do
20
20
 
21
- before { Thread.stub(:new).and_return(double) }
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async_io
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antonio C Nalesso