async-bus 0.1.0 → 0.2.0

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.
@@ -1,61 +0,0 @@
1
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require_relative 'proxy'
22
-
23
- module Async
24
- module Bus
25
- class Local
26
- def initialize
27
- @instances = {}
28
- end
29
-
30
- def close
31
- @instances.clear
32
- end
33
-
34
- def []= name, instance
35
- @instances[name] = instance
36
-
37
- Proxy.new(self, name, instance)
38
- end
39
-
40
- def [] name
41
- Proxy.new(self, name, @instances[name])
42
- end
43
-
44
- class Proxy < Bus::Proxy
45
- def initialize(name, bus, instance)
46
- super(name, bus)
47
-
48
- @instance = instance
49
- end
50
-
51
- def method_missing(name, *args, &block)
52
- @instance.send(name, *args, &block)
53
- end
54
-
55
- def respond_to?(*args)
56
- @instance.respond_to?(*args)
57
- end
58
- end
59
- end
60
- end
61
- end
@@ -1,69 +0,0 @@
1
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require_relative 'proxy'
22
-
23
- module Async
24
- module Bus
25
- class Remote
26
- def initialize(connection)
27
- @connection = connection
28
- end
29
-
30
- def close
31
- @instances.clear
32
- end
33
-
34
- def []= name, instance
35
- @instances[name] = instance
36
-
37
- @connection.
38
-
39
- Proxy.new(self, name, instance)
40
- end
41
-
42
- def [] name
43
- Proxy.new(self, name, @instances[name])
44
- end
45
-
46
- def invoke(name, *arguments, **options, &block)
47
- @connection.invoke(name, arguments, options, block_given?) do |transaction|
48
- while response = transaction.read
49
- what, *arguments = response
50
-
51
- case what
52
- when :error
53
- raise(*arguments)
54
- when :return
55
- return(*arguments)
56
- when :yield
57
- begin
58
- result = yield(*arguments)
59
- transaction.write(:next, result)
60
- rescue => error
61
- transaction.write(:error, error)
62
- end
63
- end
64
- end
65
- end
66
- end
67
- end
68
- end
69
- end