tribe 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/tribe/actor.rb CHANGED
@@ -15,7 +15,7 @@ module Tribe
15
15
  end
16
16
 
17
17
  def enqueue(command, data = nil)
18
- return false unless @alive
18
+ return false unless alive?
19
19
 
20
20
  @mailbox.push(Workers::Event.new(command, data))
21
21
 
@@ -55,9 +55,18 @@ module Tribe
55
55
  process_event(event)
56
56
  end
57
57
  end
58
+
58
59
  rescue Exception => e
59
60
  @alive = false
60
61
  exception_handler(e)
62
+ ensure
63
+ @mailbox.release do
64
+ @pool.perform do
65
+ process_events
66
+ end
67
+ end
68
+
69
+ return nil
61
70
  end
62
71
 
63
72
  #
@@ -65,7 +74,7 @@ module Tribe
65
74
  #
66
75
 
67
76
  def process_event(event)
68
- puts "Actor (#{identifier}) received event (#{event.inspect})."
77
+ puts "Actor (#{identifier}) processing event (#{event.inspect}) using thread (#{Thread.current.object_id})."
69
78
  end
70
79
 
71
80
  def exception_handler(e)
data/lib/tribe/mailbox.rb CHANGED
@@ -13,14 +13,48 @@ module Tribe
13
13
 
14
14
  def shift
15
15
  @mutex.synchronize do
16
+ return nil if @current_thread && @current_thread != Thread.current
17
+
18
+ @current_thread = Thread.current unless @current_thread
19
+
16
20
  @messages.shift
17
21
  end
18
22
  end
19
23
 
24
+ def release(&requeue_block)
25
+ @mutex.synchronize do
26
+ @current_thread = nil
27
+
28
+ if requeue_block && @messages.length > 0
29
+ requeue_block.call
30
+ end
31
+ end
32
+ end
33
+
20
34
  def synchronize(&block)
21
35
  @mutex.synchronize do
22
36
  block.call
23
37
  end
24
38
  end
39
+
40
+ # def obtain
41
+ # @mutex.synchronize do
42
+ # return false if @current_thread && @current_thread != Thread.current
43
+
44
+ # @current_thread = Thread.current
45
+
46
+ # return true
47
+ # end
48
+ # end
49
+
50
+ # def release
51
+ # @mutex.synchronize do
52
+ # return false unless @current_thread && @current_thread == Thread.current
53
+
54
+ # @current_thread = nil
55
+
56
+ # return true
57
+ # end
58
+ # end
25
59
  end
26
60
  end
data/lib/tribe/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tribe
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tribe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: