pipe_rpc 2.2.1 → 2.2.2

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: 38d81befe0835cd840ef1984f9df80e37fd9648c
4
- data.tar.gz: b131d78842fad4c0df6ad70584583a3f7d7c592e
3
+ metadata.gz: ee330bfeecf7d6643745bba563427b7ef8f80b13
4
+ data.tar.gz: e3b940e58c316efe2bde2a9165bd6d692c113abf
5
5
  SHA512:
6
- metadata.gz: 1b97ab5db07bb699cb490bb01c1a0d05c3cbaa7cd9e32b1bff37304ed630d5e8600c64be65004609fe185dfd851602d218aa3ddc157cde351f35f1e14c549b13
7
- data.tar.gz: eda62283c83632b3ddf4b663f7d9d43934edae49e4ab8fc9296ac3e8ee40c82f24f4c32cb410764445a1b39a8dae262ba0565196984ada4828c33794515e679e
6
+ metadata.gz: beaff9f942564a862ec5923ad37b88dbd7e20896d2124c1b2dbcf681611dcac51f5bf180746f80f5678548a7ce80a36e0bce2b927d9b1dd8a64d9724cbb53a3d
7
+ data.tar.gz: 47329a0a0b9024a6ca3cc922350bcb26837503a94d77641f01b83b7880c80f5f90a476718644f86f62c8b703c5aafa9c9d4e757460da3be34c2949140ffd3f1b
@@ -24,12 +24,20 @@ module PipeRpc
24
24
  @hub.socket.on_sent(&on_sent)
25
25
  end
26
26
 
27
+ def off_sent(on_sent)
28
+ @hub.socket.off_sent(on_sent)
29
+ end
30
+
27
31
  def on_received(&on_received)
28
32
  @hub.socket.on_received(&on_received)
29
33
  end
30
34
 
31
- def close
32
- @hub.socket.close
35
+ def off_received(on_received)
36
+ @hub.socket.off_received(on_received)
37
+ end
38
+
39
+ def close(reason = 'manually closed')
40
+ @hub.socket.close(reason)
33
41
  end
34
42
 
35
43
  def handle_message
@@ -6,10 +6,11 @@ module PipeRpc
6
6
  @output = args.fetch(:output)
7
7
  @on_sent = []
8
8
  @on_received = []
9
+ @closed_reason = "lost connection to other side"
9
10
  end
10
11
 
11
12
  def read
12
- raise ClosedError if @input.closed?
13
+ raise ClosedError.new(@closed_reason) if @input.closed?
13
14
 
14
15
  # infinite #readpartial that also works with mruby-restricted_io
15
16
  packed = ''
@@ -26,7 +27,7 @@ module PipeRpc
26
27
  end
27
28
 
28
29
  def write(obj)
29
- raise ClosedError if @output.closed?
30
+ raise ClosedError.new(@closed_reason) if @output.closed?
30
31
  payload = obj.to_h
31
32
  @on_sent.each{ |callback| callback.call(payload) }
32
33
  @output.syswrite payload.to_msgpack
@@ -34,13 +35,24 @@ module PipeRpc
34
35
 
35
36
  def on_sent(&on_sent)
36
37
  @on_sent << on_sent
38
+ on_sent
39
+ end
40
+
41
+ def off_sent(callback)
42
+ @on_sent.delete(callback)
37
43
  end
38
44
 
39
45
  def on_received(&on_received)
40
46
  @on_received << on_received
47
+ on_received
48
+ end
49
+
50
+ def off_received(callback)
51
+ @on_received.delete(callback)
41
52
  end
42
53
 
43
- def close
54
+ def close(reason)
55
+ @closed_reason = reason
44
56
  @input.close
45
57
  @output.close
46
58
  end
@@ -1,3 +1,3 @@
1
1
  module PipeRpc
2
- VERSION = "2.2.1"
2
+ VERSION = "2.2.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pipe_rpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Aue
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-13 00:00:00.000000000 Z
11
+ date: 2016-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack