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 +11 -2
- data/lib/tribe/mailbox.rb +34 -0
- data/lib/tribe/version.rb +1 -1
- metadata +1 -1
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
|
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})
|
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