rgossip2 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/rgossip2/context_helper.rb +21 -2
  2. metadata +3 -3
@@ -20,18 +20,37 @@ module RGossip2
20
20
  # 各種ハンドラプロキシメソッド
21
21
  def callback(action, address, timestamp, data)
22
22
  if @context.callback_handler
23
- @context.callback_handler.yield([action, address, timestamp, data])
23
+ __proc_yield_protect__(@context.callback_handler, action, address, timestamp, data)
24
24
  end
25
25
  end
26
26
 
27
27
  def handle_error(e)
28
28
  if @context.error_handler
29
- @context.error_handler.yield(e)
29
+ __proc_yield_protect__(@context.error_handler, e)
30
30
  else
31
31
  raise e
32
32
  end
33
33
  end
34
34
 
35
+ def __proc_yield_protect__(proc, *args)
36
+ case proc.arity
37
+ when 0
38
+ proc.call
39
+ when 1
40
+ proc.call((args.length < 2) ? args.first : args)
41
+ else
42
+ proc.call(*args)
43
+ end
44
+ rescue Exception => e
45
+ message = (["#{e.class}: #{e.message}"] + (e.backtrace || [])).join("\n\tfrom ")
46
+
47
+ if @context.logger
48
+ @context.logger.error(message)
49
+ else
50
+ $stderr.puts(message)
51
+ end
52
+ end
53
+
35
54
  # ノード情報群からハッシュ値とメッセージを生成する
36
55
  def digest_and_message(nodes)
37
56
  message = nodes.map {|i| i.to_a }.to_msgpack
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgossip2
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - winebarrel