pb_actor 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: ed926fafad75713c566df0ac82704631c29ecff0
4
- data.tar.gz: 7d74986b42da2262ba4dc3a04d3786a47996c2e0
3
+ metadata.gz: 171981023e291918c5a970e7f33062035e0c8542
4
+ data.tar.gz: d687fbe4a94c60505e4c765f56067d33f20cd752
5
5
  SHA512:
6
- metadata.gz: a1268f95cb59df589117fad9822cf02c433c1cd1ffb611ead131377aecaf97def664979f60d2725a61f4f46f9dab17524f44e469912d0e525970eda6bc4b5fc0
7
- data.tar.gz: f6d686f57c195f8ab3cd6400163b6905402df5b31b1a1b2f8b42b2af413a943e34b98c018b935e3c942761b7b0608cf42eb790e55560524fd69613a495dfba87
6
+ metadata.gz: 4222d61838e6118b282efcba9449531d8000b9d79ccc1769b536f4667d5f9965178de18298e673a52679b4930ff4425c6d384eebd0fab49d8db922263fc522fd
7
+ data.tar.gz: 3014b7618e9cdaab4b9ee3670a3c9d2aab50bddd601ce3fb9df40fe28c3404480a24e61058e9526be26cd2023dfeeecfd417ce463e2f2b8c66f38149a0bec6f7
@@ -6,6 +6,10 @@ module PbActor
6
6
  def included base
7
7
  base.send :extend, ClassMethods
8
8
  end
9
+
10
+ def dead_actor_msg
11
+ 'dead actor call'
12
+ end
9
13
  end
10
14
 
11
15
  module ClassMethods
@@ -4,17 +4,22 @@ module PbActor
4
4
  class BasicProxy
5
5
  def initialize origin, pid, wr, rd
6
6
  @origin, @pid, @wr, @rd = origin, pid, wr, rd
7
+ @alive = true
7
8
  end
8
9
 
9
10
  def alive?
10
- !Process.waitpid @pid, Process::WNOHANG
11
+ if !@alive || (!Process.waitpid @pid, Process::WNOHANG)
12
+ @alive
13
+ else
14
+ @alive = false
15
+ end
11
16
  rescue Errno::ECHILD => e
12
- false
17
+ @alive = false
13
18
  end
14
19
 
15
20
  def method_missing method, *args, &blk
16
21
  raise ArgumentError, 'actor not support block' if blk
17
- raise DeadActorError, 'dead actor call' unless alive?
22
+ raise DeadActorError, PbActor.dead_actor_msg unless alive?
18
23
  end
19
24
 
20
25
  def to_s
@@ -4,13 +4,13 @@ module PbActor
4
4
  def send msg, wr
5
5
  Marshal.dump(msg, wr)
6
6
  rescue Errno::EPIPE => e
7
- raise DeadActorError, 'dead actor call'
7
+ raise DeadActorError, PbActor.dead_actor_msg
8
8
  end
9
9
 
10
10
  def recv rd
11
11
  Marshal.load rd
12
12
  rescue EOFError => e
13
- raise DeadActorError, 'dead actor call'
13
+ raise DeadActorError, PbActor.dead_actor_msg
14
14
  end
15
15
  end
16
16
  end
@@ -39,6 +39,7 @@ module PbActor
39
39
  [cr, cw].each &:close
40
40
  @rd = pr
41
41
  @wr = pw
42
+ @alive = true
42
43
  end
43
44
 
44
45
  def method_missing method, *args, &blk
@@ -55,15 +56,21 @@ module PbActor
55
56
  end
56
57
 
57
58
  def terminate
59
+ raise DeadActorError, PbActor.dead_actor_msg unless alive?
58
60
  Message.send [:terminate], @wr
59
61
  Process.wait @pid
60
62
  nil
63
+ rescue Errno::ECHILD => e
64
+ raise DeadActorError, PbActor.dead_actor_msg
61
65
  end
62
66
 
63
67
  def terminate!
68
+ raise DeadActorError, PbActor.dead_actor_msg unless alive?
64
69
  Process.kill "KILL", @pid
65
70
  Process.wait @pid
66
71
  nil
72
+ rescue Errno::ECHILD, Errno::ESRCH => e
73
+ raise DeadActorError, PbActor.dead_actor_msg
67
74
  end
68
75
  end
69
76
  end
@@ -1,3 +1,3 @@
1
1
  module PbActor
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -62,6 +62,7 @@ describe PbActor do
62
62
  @test.terminate
63
63
  @test.alive?.should == false
64
64
  expect{@test.foo}.to raise_error(PbActor::DeadActorError)
65
+ expect{@test.terminate}.to raise_error(PbActor::DeadActorError)
65
66
  end
66
67
 
67
68
  it 'terminate! should work' do
@@ -71,6 +72,7 @@ describe PbActor do
71
72
  @test.alive? == false
72
73
  end
73
74
  @test.alive?.should == false
75
+ expect{@test.terminate!}.to raise_error(PbActor::DeadActorError)
74
76
  end
75
77
 
76
78
  it 'to_s should correct' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pb_actor
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
  - jjy