async_io 0.0.3 → 0.0.4
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 +16 -9
- data/lib/async_io/version.rb +1 -1
- data/lib/async_io.rb +5 -1
- data/spec/async_io/base_spec.rb +4 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e768d314c92eac6b9cfc337526f1ac1ae05f11f6
|
4
|
+
data.tar.gz: 8bf2812033baa2729bfc2e1ba980b10f3fa0a759
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a21e691691577890b5bbcb3a05dcda8356a3d420a675d337ebbfa3704b686e4a6b7eabc29e962d8ee6a42bc79cb9540ce18c54803334dd4eed7d341a86b838e1
|
7
|
+
data.tar.gz: b10b690d35df4cea199cb0be527d054bdb1582c36fa95db246f7949a51d105de6868019cbdc9616b64e64489d1c922dc1833aee88cd9f395dffd4c357be60a9a
|
data/lib/async_io/base.rb
CHANGED
@@ -8,11 +8,9 @@ module AsyncIO
|
|
8
8
|
|
9
9
|
##
|
10
10
|
# Default:
|
11
|
-
# Number of threads to be spanwed is
|
11
|
+
# Number of threads to be spanwed is 5
|
12
12
|
#
|
13
|
-
# NOTE:
|
14
|
-
# 'getting' a job done will not be raised at all.
|
15
|
-
# Instead it will be logged to a specified log file.
|
13
|
+
# NOTE:
|
16
14
|
#
|
17
15
|
# Whenever an exception is raised, the thread that the
|
18
16
|
# exception was raised from is killed, so we need a
|
@@ -21,9 +19,9 @@ module AsyncIO
|
|
21
19
|
#
|
22
20
|
attr_reader :queue, :threads
|
23
21
|
attr_accessor :logger
|
24
|
-
def initialize(n_threads=
|
25
|
-
@logger =
|
26
|
-
@queue =
|
22
|
+
def initialize(n_threads = 5, args = { logger: AsyncIO::Logger, queue: Queue.new })
|
23
|
+
@logger = args[:logger]
|
24
|
+
@queue = args[:queue]
|
27
25
|
@threads = []
|
28
26
|
n_threads.times { @threads << Thread.new { consumer } }
|
29
27
|
end
|
@@ -75,7 +73,7 @@ module AsyncIO
|
|
75
73
|
# whenever you send a message +job+ to it. Once
|
76
74
|
# job is finished you will be able to get its result.
|
77
75
|
#
|
78
|
-
def worker(payload,
|
76
|
+
def worker(payload, job)
|
79
77
|
rescuer do
|
80
78
|
Worker.new(payload, job).tap { |w|
|
81
79
|
queue.push(w)
|
@@ -90,9 +88,18 @@ module AsyncIO
|
|
90
88
|
# and empty job. ( i.e empty block of code )
|
91
89
|
#
|
92
90
|
def async(&payload)
|
93
|
-
worker(payload
|
91
|
+
worker(payload, proc {})
|
94
92
|
end
|
95
93
|
|
94
|
+
def async_with(job)
|
95
|
+
worker(proc {}, job)
|
96
|
+
end
|
97
|
+
|
98
|
+
##
|
99
|
+
# TODO:
|
100
|
+
# Allow multiple intervals to run on the same thread by storing
|
101
|
+
# them in a list, and calling them later on.
|
102
|
+
#
|
96
103
|
def interval(seconds)
|
97
104
|
new_interval? do
|
98
105
|
while true
|
data/lib/async_io/version.rb
CHANGED
data/lib/async_io.rb
CHANGED
@@ -26,8 +26,12 @@ module AsyncIO
|
|
26
26
|
# how it is available within a block later on.
|
27
27
|
# NOTE: You must pass a job ( i.e ruby block ).
|
28
28
|
#
|
29
|
-
def self.async(payload =
|
29
|
+
def self.async(payload = proc{}, &job)
|
30
30
|
async_creator.worker(payload, &job)
|
31
31
|
end
|
32
32
|
|
33
|
+
def self.async_with(job)
|
34
|
+
async_creator.async_with(job)
|
35
|
+
end
|
36
|
+
|
33
37
|
end
|
data/spec/async_io/base_spec.rb
CHANGED
@@ -29,7 +29,7 @@ describe AsyncIO::Base do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should create 1 thread as default" do
|
32
|
-
alien.threads.size.should eq
|
32
|
+
alien.threads.size.should eq 5
|
33
33
|
end
|
34
34
|
|
35
35
|
end
|
@@ -40,25 +40,13 @@ describe AsyncIO::Base do
|
|
40
40
|
alien.should respond_to :worker
|
41
41
|
end
|
42
42
|
|
43
|
-
it "should_not raise_error when no block is passed" do
|
44
|
-
expect {
|
45
|
-
alien.worker(:jason)
|
46
|
-
}.to_not raise_error
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should not raise_error when block is passed" do
|
50
|
-
expect {
|
51
|
-
alien.worker(:lizza) { }
|
52
|
-
}.to_not raise_error
|
53
|
-
end
|
54
|
-
|
55
43
|
it "should push worker onto the queue" do
|
56
|
-
alien.worker(:paul
|
44
|
+
alien.worker(:paul, proc {})
|
57
45
|
alien.extract_size!.should eq(1)
|
58
46
|
end
|
59
47
|
|
60
48
|
it "should return worker" do
|
61
|
-
result = alien.worker(:blunt
|
49
|
+
result = alien.worker(:blunt, proc {})
|
62
50
|
result.should be_instance_of AsyncIO::Worker
|
63
51
|
end
|
64
52
|
end
|
@@ -98,7 +86,7 @@ describe AsyncIO::Base do
|
|
98
86
|
#
|
99
87
|
alien.async(&payload)
|
100
88
|
|
101
|
-
alien.should have_received(:worker).with(payload)
|
89
|
+
alien.should have_received(:worker).with( payload, kind_of(Proc) )
|
102
90
|
end
|
103
91
|
end
|
104
92
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async_io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Antonio C Nalesso
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|