standard-procedure-plumbing 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +24 -2
- data/checksums/standard-procedure-plumbing-0.3.1.gem.sha512 +1 -0
- data/lib/plumbing/valve/async.rb +1 -0
- data/lib/plumbing/valve/inline.rb +1 -0
- data/lib/plumbing/valve.rb +2 -2
- data/lib/plumbing/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: 9a111ce599942b5e33b6928cede476b75e56fd6574625bf50ca82d6d75f3e718
|
4
|
+
data.tar.gz: b1b4c48062aec9d77ec3b917c25723fae8ff2cc4075d9f91c699da3f165b7c84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d2de706d57ef380e67fcd9d79b3d202ca0741f7ed24552ad62bc63944f1c0a82cdd6123560a6d79a85099218db5c9c966ee602a0ef281ea7d5b0305e1f5a707
|
7
|
+
data.tar.gz: 47de86307b817c0d0399bc06bcac5f78eea3629b93725b785f1dc6a442a300a03ceadde6627f2d198ea296524f584f29a90fa3ec52e5e635507c024241fec5da
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -156,7 +156,12 @@ An [actor](https://en.wikipedia.org/wiki/Actor_model) defines the messages an ob
|
|
156
156
|
|
157
157
|
[Plumbing::Valve](/lib/plumbing/valve.rb) ensures that all messages received are channelled into a concurrency-safe queue. This allows you to take an existing class and ensures that messages received via its public API are made concurrency-safe.
|
158
158
|
|
159
|
-
Include the Plumbing::Valve module into your class, define the messages the objects can respond to and set the `Plumbing` configuration to set the desired concurrency model. Messages themselves are split into two categories: commands and queries.
|
159
|
+
Include the Plumbing::Valve module into your class, define the messages the objects can respond to and set the `Plumbing` configuration to set the desired concurrency model. Messages themselves are split into two categories: commands and queries.
|
160
|
+
|
161
|
+
- Commands have no return value so when the message is sent, the caller does not block, the task is called asynchronously and the caller continues immediately
|
162
|
+
- Queries return a value so the caller blocks until the actor has returned a value
|
163
|
+
- However, if you call a query and pass `ignore_result: true` then the query will not block, although you will not be able to access the return value - this is for commands that do something and then return a result based on that work (which you may or may not be interested in - see Plumbing::Pipe#add_observer)
|
164
|
+
- None of the above applies if the `Plumbing mode` is set to `:inline` (which is the default) - in this case, the actor behaves like normal ruby code
|
160
165
|
|
161
166
|
Instead of constructing your object with `.new`, use `.start`. This builds a proxy object that wraps the target instance and dispatches messages through a safe mechanism. Only messages that have been defined as part of the valve are available in this proxy - so you don't have to worry about callers bypassing the valve's internal context.
|
162
167
|
|
@@ -175,7 +180,7 @@ Also be aware that if you use valves in one place, you need to use them everywhe
|
|
175
180
|
attr_reader :name, :job_title
|
176
181
|
|
177
182
|
include Plumbing::Valve
|
178
|
-
query :name, :job_title
|
183
|
+
query :name, :job_title, :greet_slowly
|
179
184
|
command :promote
|
180
185
|
|
181
186
|
def initialize(name)
|
@@ -187,6 +192,11 @@ Also be aware that if you use valves in one place, you need to use them everywhe
|
|
187
192
|
sleep 0.5
|
188
193
|
@job_title = "Sales manager"
|
189
194
|
end
|
195
|
+
|
196
|
+
def greet_slowly
|
197
|
+
sleep 0.2
|
198
|
+
"H E L L O"
|
199
|
+
end
|
190
200
|
end
|
191
201
|
```
|
192
202
|
|
@@ -206,6 +216,12 @@ Also be aware that if you use valves in one place, you need to use them everywhe
|
|
206
216
|
# this will block for 0.5 seconds
|
207
217
|
puts @person.job_title
|
208
218
|
# => "Sales manager"
|
219
|
+
|
220
|
+
@person.greet_slowly
|
221
|
+
# this will block for 0.2 seconds before returning "H E L L O"
|
222
|
+
|
223
|
+
@person.greet_slowly(ignore_result: true)
|
224
|
+
# this will block for 0.2 seconds (as the mode is :inline) before returning nil
|
209
225
|
```
|
210
226
|
|
211
227
|
[Using fibers](/spec/examples/valve_spec.rb) with concurrency but no parallelism
|
@@ -226,6 +242,12 @@ Also be aware that if you use valves in one place, you need to use them everywhe
|
|
226
242
|
# this will return immediately without blocking
|
227
243
|
puts @person.job_title
|
228
244
|
# => "Sales manager" (this will block for 0.5s because #job_title query will not start until the #promote command has completed)
|
245
|
+
|
246
|
+
@person.greet_slowly
|
247
|
+
# this will block for 0.2 seconds before returning "H E L L O"
|
248
|
+
|
249
|
+
@person.greet_slowly(ignore_result: true)
|
250
|
+
# this will not block and returns nil
|
229
251
|
```
|
230
252
|
|
231
253
|
## Plumbing::Pipe - a composable observer
|
@@ -0,0 +1 @@
|
|
1
|
+
966c4bcf848d26272cf0b3bb3d74c9724aa9899a8bcbf5e25a6ce20608de1f529dc766056aa0cb99fbe1c7d6e16afe72acbcc0619fc14f57f01eb7921be7b653
|
data/lib/plumbing/valve/async.rb
CHANGED
data/lib/plumbing/valve.rb
CHANGED
@@ -51,8 +51,8 @@ module Plumbing
|
|
51
51
|
def build_proxy_class
|
52
52
|
Class.new(proxy_base_class).tap do |proxy_class|
|
53
53
|
queries.each do |query|
|
54
|
-
proxy_class.define_method query do |*args, **params, &block|
|
55
|
-
ask(query, *args, **params, &block)
|
54
|
+
proxy_class.define_method query do |*args, ignore_result: false, **params, &block|
|
55
|
+
ignore_result ? tell(query, *args, **params, &block) : ask(query, *args, **params, &block)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
data/lib/plumbing/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: standard-procedure-plumbing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rahoul Baruah
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A composable event pipeline and sequential pipelines of operations
|
14
14
|
email:
|
@@ -33,6 +33,7 @@ files:
|
|
33
33
|
- checksums/standard-procedure-plumbing-0.2.1.gem.sha512
|
34
34
|
- checksums/standard-procedure-plumbing-0.2.2.gem.sha512
|
35
35
|
- checksums/standard-procedure-plumbing-0.3.0.gem.sha512
|
36
|
+
- checksums/standard-procedure-plumbing-0.3.1.gem.sha512
|
36
37
|
- lib/plumbing.rb
|
37
38
|
- lib/plumbing/config.rb
|
38
39
|
- lib/plumbing/custom_filter.rb
|