interop 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/interop/rpc/base.rb +6 -3
- data/lib/interop/task_group.rb +32 -0
- data/lib/interop/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c223f2bcb37a0232a64aada70c36947472db2cb1f3f93f4c240f8ef506521244
|
4
|
+
data.tar.gz: c138b462718e569d020a416451a89b81b8a04ed8a100cba3a528bf39b03c82f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 220ec6f89e51f1ffdc00657ff52f2a1d16a143dad472b5604c396adfb83748b3bb037203d79df524625c33b2c17232f80cf61045a05a2af6ba4a1792a41d1976
|
7
|
+
data.tar.gz: 7e24d2f42c7346248e14d04a981c0480f60746901272e9c01cbbbde442900fd2b151e02785bad850d112879d5a58abf545cf88baddc14f2f4abe39f0bc80f51c
|
data/lib/interop/rpc/base.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
require 'interop/connection'
|
2
2
|
require 'interop/rpc/dispatcher'
|
3
3
|
require 'interop/rpc/controller'
|
4
|
+
require 'interop/task_group'
|
4
5
|
|
5
6
|
module Hx
|
6
7
|
module Interop
|
7
8
|
module RPC
|
8
9
|
# Base class for RPC Client and Server
|
9
10
|
class Base
|
10
|
-
def initialize(reader, writer = reader)
|
11
|
+
def initialize(reader, writer = reader, task_group: TaskGroup.new)
|
11
12
|
@connection = Connection.build(reader, writer)
|
12
13
|
@dispatcher = Dispatcher.new
|
14
|
+
@tasks = task_group
|
13
15
|
yield self if block_given?
|
14
16
|
@io_thread = Thread.new do
|
15
17
|
run
|
@@ -20,7 +22,8 @@ module Hx
|
|
20
22
|
|
21
23
|
# TODO: custom exception handler?
|
22
24
|
|
23
|
-
# Wait for the process to finish (i.e. for the connection to close).
|
25
|
+
# Wait for the process to finish (i.e. for the connection to close). Does not wait for running requests/event
|
26
|
+
# handlers to complete.
|
24
27
|
def wait
|
25
28
|
@io_thread.join
|
26
29
|
raise @error if @error # TODO: wrap in something specific, to preserve backtrace
|
@@ -48,7 +51,7 @@ module Hx
|
|
48
51
|
|
49
52
|
def run
|
50
53
|
@connection.read_all do |request|
|
51
|
-
|
54
|
+
@tasks.run do
|
52
55
|
yield request
|
53
56
|
rescue StandardError => e
|
54
57
|
@io_thread.raise e
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Hx
|
2
|
+
module Interop
|
3
|
+
# Allows blocking on running tasks
|
4
|
+
class TaskGroup
|
5
|
+
def initialize
|
6
|
+
@count = 0
|
7
|
+
@mutex = Mutex.new
|
8
|
+
@condition = ConditionVariable.new
|
9
|
+
end
|
10
|
+
|
11
|
+
# Run the given block in a new thread. Calls to #wait will block until it has finished running.
|
12
|
+
def run
|
13
|
+
@mutex.synchronize { @count += 1 }
|
14
|
+
Thread.new do
|
15
|
+
yield
|
16
|
+
ensure
|
17
|
+
@mutex.synchronize do
|
18
|
+
@count -= 1
|
19
|
+
@condition.broadcast if @count.zero?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Block until all threads created by #run have finished.
|
25
|
+
def wait
|
26
|
+
@mutex.synchronize do
|
27
|
+
@condition.wait(@mutex) while @count.positive?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/interop/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: interop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Neil E. Pearson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby implementation of hx/interop cross-language interop abstraction
|
14
14
|
email:
|
@@ -43,6 +43,7 @@ files:
|
|
43
43
|
- lib/interop/stream_adapter.rb
|
44
44
|
- lib/interop/stream_reader.rb
|
45
45
|
- lib/interop/stream_writer.rb
|
46
|
+
- lib/interop/task_group.rb
|
46
47
|
- lib/interop/version.rb
|
47
48
|
- lib/interop/writer.rb
|
48
49
|
homepage: https://github.com/hx/interop
|