mailbox 0.1.6 → 0.1.7
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/.gitignore +2 -0
- data/VERSION.yml +3 -2
- data/lib/mailbox.rb +14 -2
- data/mailbox.gemspec +2 -2
- data/test/mailbox_test.rb +27 -1
- metadata +2 -2
data/.gitignore
CHANGED
data/VERSION.yml
CHANGED
data/lib/mailbox.rb
CHANGED
@@ -75,10 +75,14 @@ module Mailbox
|
|
75
75
|
# will be a +mailslot+. If <tt>:channel</tt> is provided
|
76
76
|
# the next method will become a subscriber on the channel.
|
77
77
|
# Channel based +mailslot+ methods are also made private
|
78
|
-
# to discourage direct invocation
|
78
|
+
# to discourage direct invocation. <tt>:exception</tt>
|
79
|
+
# can be provided as the symbol for a method to handle
|
80
|
+
# any exceptions that occur in your +mailslot+. This
|
81
|
+
# method will be passed the exception that was raised
|
79
82
|
def mailslot(params={})
|
80
83
|
@next_channel_name = params[:channel]
|
81
84
|
@replyable = params[:replyable]
|
85
|
+
@exception = params[:exception]
|
82
86
|
@mailslot = true
|
83
87
|
end
|
84
88
|
|
@@ -104,8 +108,16 @@ module Mailbox
|
|
104
108
|
alias_method :"__#{method_name}__", method_name
|
105
109
|
@is_adding_mailbox_to_method = true
|
106
110
|
|
111
|
+
exception_method, @exception = @exception, nil
|
107
112
|
define_method( method_name, lambda do |*args|
|
108
|
-
__fiber__.execute
|
113
|
+
__fiber__.execute do
|
114
|
+
begin
|
115
|
+
self.send(:"__#{method_name}__", *args )
|
116
|
+
rescue Exception => ex
|
117
|
+
raise if exception_method.nil?
|
118
|
+
self.send(:"#{exception_method}", ex)
|
119
|
+
end
|
120
|
+
end
|
109
121
|
end )
|
110
122
|
|
111
123
|
@is_adding_mailbox_to_method = false
|
data/mailbox.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mailbox}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Joel Friedman", "Patrick Farley"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-02-26}
|
13
13
|
s.description = %q{Mailbox is a JRuby module that simplifies concurrency and is backed by JVM threads.}
|
14
14
|
s.email = %q{asher.friedman@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/test/mailbox_test.rb
CHANGED
@@ -20,7 +20,34 @@ class MailboxTest < Test::Unit::TestCase
|
|
20
20
|
|
21
21
|
assert( latch.await( 1, Latches::TimeUnit::SECONDS ), "Timed out" )
|
22
22
|
assert_not_equal JThread.current_thread.name, thread_info[:name]
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_can_set_mailslot_to_callback_on_exception
|
26
|
+
klass = Class.new do
|
27
|
+
include Mailbox
|
28
|
+
|
29
|
+
attr_accessor :ex
|
30
|
+
|
31
|
+
def initialize(latch)
|
32
|
+
@latch = latch
|
33
|
+
end
|
34
|
+
|
35
|
+
mailslot :exception => :handle_exception
|
36
|
+
def test_method
|
37
|
+
raise "test exception"
|
38
|
+
end
|
39
|
+
|
40
|
+
def handle_exception(ex)
|
41
|
+
@ex = ex
|
42
|
+
@latch.count_down
|
43
|
+
end
|
44
|
+
end
|
23
45
|
|
46
|
+
latch = Latches::CountDownLatch.new( 1 )
|
47
|
+
clazz = klass.new(latch)
|
48
|
+
clazz.test_method
|
49
|
+
assert( latch.await( 1, Latches::TimeUnit::SECONDS ), "Timed out" )
|
50
|
+
assert_equal "test exception", clazz.ex.message
|
24
51
|
end
|
25
52
|
|
26
53
|
def test_default_is_run_asynchronously
|
@@ -46,7 +73,6 @@ class MailboxTest < Test::Unit::TestCase
|
|
46
73
|
ensure
|
47
74
|
Mailbox.synchronous = false;
|
48
75
|
end
|
49
|
-
|
50
76
|
end
|
51
77
|
|
52
78
|
def test_should_support_channels
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Friedman
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2010-
|
13
|
+
date: 2010-02-26 00:00:00 -06:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|