async_io 0.0.4 → 0.0.5

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: e768d314c92eac6b9cfc337526f1ac1ae05f11f6
4
- data.tar.gz: 8bf2812033baa2729bfc2e1ba980b10f3fa0a759
3
+ metadata.gz: 589bbfd6ddea54eacdcfb7d11444a98c69ebb135
4
+ data.tar.gz: 420bbac2e0bebdfd57aa1b18d90194cdcabd2b15
5
5
  SHA512:
6
- metadata.gz: a21e691691577890b5bbcb3a05dcda8356a3d420a675d337ebbfa3704b686e4a6b7eabc29e962d8ee6a42bc79cb9540ce18c54803334dd4eed7d341a86b838e1
7
- data.tar.gz: b10b690d35df4cea199cb0be527d054bdb1582c36fa95db246f7949a51d105de6868019cbdc9616b64e64489d1c922dc1833aee88cd9f395dffd4c357be60a9a
6
+ metadata.gz: 6abe1c74a64b278ae7a0752177099f51863a25bd2e09890c54332e69259c2eed1ea3b269ecc1707c27054784ff160d4b81995fdb480919d94284daa9a5a3c210
7
+ data.tar.gz: ccc8233103beacdace8692b3eb379f7dca07b3f434b9a21d57aa3f132a47a2370c65cdaea7f5cafacad2fbd16f18d9744018132e405f99707cb23c34f666520a
@@ -26,12 +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 = proc{}, &job)
30
- async_creator.worker(payload, &job)
29
+ def self.async(task = proc {}, &payload)
30
+ async_creator.worker(payload, task)
31
31
  end
32
32
 
33
- def self.async_with(job)
34
- async_creator.async_with(job)
33
+ def self.async_with(task)
34
+ async_creator.async_with(task)
35
35
  end
36
36
 
37
37
  end
@@ -42,8 +42,8 @@ module AsyncIO
42
42
 
43
43
  ##
44
44
  # It creates a new Worker, pushes it onto the queue,
45
- # whenever a 'job' (i.e a Ruby object ) is finished
46
- # it calls the payload and passes the result of job
45
+ # whenever a 'task' (i.e a Ruby object ) is finished
46
+ # it calls the payload and passes the result of that task
47
47
  # to it.
48
48
  #
49
49
  # For example:
@@ -54,45 +54,41 @@ module AsyncIO
54
54
  # end
55
55
  # end
56
56
  #
57
- # It returns the worker created for a particular job
57
+ # It returns the worker created for this particular task
58
58
  # which you could send message +done+ to it in order
59
- # to retrieve its job done.
60
- # see prediction_io/worker.rb
59
+ # to retrieve its completed task.
60
+ # see async_io/worker.rb
61
61
  #
62
62
  # For example:
63
63
  # result = aget_user(1) { |u| Logger.info(u.name) }
64
64
  #
65
- # # job may take a while to be done...
65
+ # # task may take a while to be done...
66
66
  #
67
67
  # user = result.done
68
68
  # user.name
69
69
  # => "John"
70
70
  #
71
- # NOTE: Whenever you use the snippet above, if the job
71
+ # NOTE: Whenever you use the snippet above, if the task
72
72
  # has not been finished yet you will get +false+
73
- # whenever you send a message +job+ to it. Once
74
- # job is finished you will be able to get its result.
73
+ # whenever you send a message +task+ to it. Once
74
+ # task is finished you will be able to get its result.
75
75
  #
76
- def worker(payload, job)
77
- rescuer do
78
- Worker.new(payload, job).tap { |w|
79
- queue.push(w)
80
- }
81
- end
76
+ def worker(payload, task)
77
+ Worker.new(payload, task).tap { |w| queue.push(w) }
82
78
  end
83
79
 
84
80
  ##
85
81
  # Perform any sort of task that needs to be
86
82
  # asynchronously done.
87
83
  # NOTE: It does not return anything, as it receives
88
- # and empty job. ( i.e empty block of code )
84
+ # and empty task. ( i.e empty block of code )
89
85
  #
90
86
  def async(&payload)
91
87
  worker(payload, proc {})
92
88
  end
93
89
 
94
- def async_with(job)
95
- worker(proc {}, job)
90
+ def async_with(task)
91
+ worker(proc {}, task)
96
92
  end
97
93
 
98
94
  ##
@@ -1,3 +1,3 @@
1
1
  module AsyncIo
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -6,20 +6,20 @@ module AsyncIO
6
6
  class Worker
7
7
  include AsyncIO::Rescuer
8
8
 
9
- attr_reader :payload, :job
9
+ attr_reader :payload, :task
10
10
  attr_reader :finished, :done
11
11
 
12
- def initialize(payload, job)
12
+ def initialize(payload, task)
13
13
  @payload = payload
14
- @job = job
14
+ @task = task
15
15
  @done = false
16
16
  @finished = false
17
17
  end
18
18
 
19
19
  ##
20
20
  # It sends payload a message +call+
21
- # and passes the result of a job, by sending
22
- # job a message +call+ as well, as its argument.
21
+ # and passes the result of task, by sending
22
+ # task a message +call+ as well, as its argument.
23
23
  # This allows us to do:
24
24
  #
25
25
  # aget_user(1) { |u| print u.name }
@@ -35,7 +35,7 @@ module AsyncIO
35
35
  # payload = Object.new
36
36
  # def payload.call(result); warn(result); end
37
37
  #
38
- # job is pre-definied inside a method, it can
38
+ # task is pre-definied inside a method, it can
39
39
  # be anything, for example:
40
40
  # worker(payload) do
41
41
  # User.find(uid)
@@ -43,14 +43,13 @@ module AsyncIO
43
43
  #
44
44
  def call
45
45
  try do
46
- @finished = true
47
- @done = job.call
48
- payload.call(done)
46
+ @done = task.call
47
+ payload.call(done).tap { @finished = true }
49
48
  end
50
49
  end
51
50
 
52
51
  ##
53
- # Tries to get the first job done, when an exception
52
+ # Tries to get the first task done, when an exception
54
53
  # is raised it then calls payload again passing a
55
54
  # fallback as its argument.
56
55
  #
@@ -70,7 +69,7 @@ module AsyncIO
70
69
  # from being raised.
71
70
  # It returns an instance of OpenStruct object with the
72
71
  # exception rescued ( i.e notice ) and the worker that
73
- # was assigned to this particular job.
72
+ # was assigned to this particular task.
74
73
  #
75
74
  def fallback(notice)
76
75
  OpenStruct.new({ notice: notice, worker: self })
@@ -71,19 +71,16 @@ describe AsyncIO::Base do
71
71
  # closures while using blocks.
72
72
  # The following might be helpul:
73
73
  # robertsosinski.com/2008/12/21/understanding-ruby-blocks-procs-and-lambdas
74
-
74
+ #
75
+ #
76
+ # See the link below for a better understading how to
77
+ # pass/call blocks of code in Ruby.
78
+ # pragdave.pragprog.com/pragdave/2005/11/symbolto_proc.html
75
79
  #
76
80
  it "should pass this payload block onto Worker" do
77
- payload = -> { :im_an_async_job }
78
-
81
+ payload = -> { :im_a_payload }
79
82
  worker = double
80
83
  alien.stub(:worker).and_return(worker)
81
-
82
- ##
83
- # See the link below for a better understading how to
84
- # pass/call blocks of code in Ruby.
85
- # pragdave.pragprog.com/pragdave/2005/11/symbolto_proc.html
86
- #
87
84
  alien.async(&payload)
88
85
 
89
86
  alien.should have_received(:worker).with( payload, kind_of(Proc) )
@@ -91,7 +88,7 @@ describe AsyncIO::Base do
91
88
  end
92
89
 
93
90
  context "#interval" do
94
- it "executes a job in a given interval" do
91
+ it "executes a task within a given interval" do
95
92
  alien.should_receive(:new_interval?)
96
93
  alien.interval(0.0001) { sleep(10) }
97
94
  end
@@ -9,33 +9,21 @@ module AsyncIO
9
9
  describe Worker do
10
10
 
11
11
  let(:payload) { ->(r) { r } }
12
- let(:job) { -> { :am_a_dog } }
13
- let(:worker) { Worker.new(payload, job) }
14
-
15
- context "initialising" do
16
-
17
- it "must take a payload" do
18
- worker.payload.should be_kind_of Proc
19
- end
20
-
21
- it "must take a job" do
22
- worker.job.should be_kind_of Proc
23
- end
24
-
25
- end
12
+ let(:task) { -> { :am_a_dog } }
13
+ let(:worker) { Worker.new(payload, task) }
26
14
 
27
15
  it { worker.should respond_to :done }
28
16
 
29
- it "should not be done as job is not finished" do
17
+ it "should not be done as task is not finished" do
30
18
  worker.done.should be_false
31
19
  end
32
20
 
33
- it "must call payload and pass job as its argument" do
21
+ it "must call payload and pass task as its argument" do
34
22
  worker.call.should eq(:am_a_dog)
35
23
  end
36
24
 
37
- context "Getting a job done" do
38
- it "should set done to its last finished job" do
25
+ context "Getting a task done" do
26
+ it "should set done to its last finished task" do
39
27
  worker.call
40
28
  worker.done.should eq(:am_a_dog)
41
29
  end
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.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antonio C Nalesso