standard-procedure-async 0.2.0 → 0.2.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/standard_procedure/async/actor.rb +49 -47
- data/lib/standard_procedure/async/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3aa258b93fc54c1232b652af7903b0fa85b4066aa09c442a4072c7d02d1fcf98
|
4
|
+
data.tar.gz: ef18826e86e742dcf96ac784dd654cbc9d07ce7aa71859fed83e58f488b87eca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c8168d2340e8e1ae2b5627f21c1f7a06adb0fb34845b4c1a4f0ba94e70fcd4609f2d502bd35441b0dd755ffc764a40e5ea69ae0949b20ddeb88a625bb8ea490
|
7
|
+
data.tar.gz: c0236a569b587399f419fed3b02b1991fd5d3bcbd286e514ee232f79a66e6b899b4ffbe798c622a5201c69896e1f8b8cb313c47bda2d74c75c9eaee81425a1e7
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -3,68 +3,70 @@
|
|
3
3
|
require "concurrent/array"
|
4
4
|
require "concurrent/mvar"
|
5
5
|
require "concurrent/immutable_struct"
|
6
|
+
require_relative "promises"
|
6
7
|
|
7
|
-
module StandardProcedure
|
8
|
-
module
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
module StandardProcedure
|
9
|
+
module Async
|
10
|
+
module Actor
|
11
|
+
def self.included base
|
12
|
+
base.class_eval do
|
13
|
+
def self.async name, &implementation
|
14
|
+
name = name.to_sym
|
15
|
+
implementation_name = :"_#{name}"
|
12
16
|
|
13
|
-
|
14
|
-
|
15
|
-
|
17
|
+
define_method name do |*args, **params|
|
18
|
+
_add_message_to_queue(implementation_name, *args, **params)
|
19
|
+
end
|
20
|
+
|
21
|
+
define_method implementation_name do |*args, **params|
|
22
|
+
instance_exec(*args, **params, &implementation)
|
23
|
+
rescue => ex
|
24
|
+
ex
|
25
|
+
end
|
26
|
+
end
|
16
27
|
end
|
17
28
|
end
|
18
|
-
end
|
19
29
|
|
20
|
-
|
21
|
-
def async name, &implementation
|
22
|
-
name = name.to_sym
|
23
|
-
implementation_name = :"_#{name}"
|
24
|
-
|
25
|
-
define_method name.to_sym do |*args, &block|
|
26
|
-
_add_message_to_queue(implementation_name, *args, &block)
|
27
|
-
end
|
30
|
+
private
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
+
def _messages
|
33
|
+
@_messages ||= Concurrent::Array.new
|
32
34
|
end
|
33
|
-
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
def _promises
|
37
|
+
@_promises ||= StandardProcedure::Async::Promises.new
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
def _add_message_to_queue name, *args, **params, &block
|
41
|
+
message = Message.new(self, name, args, params, block, Concurrent::MVar.new)
|
42
|
+
_messages << message
|
43
|
+
_perform_messages if _messages.count == 1
|
44
|
+
message
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
def _perform_messages
|
48
|
+
_promises.future do
|
49
|
+
while (message = _messages.shift)
|
50
|
+
message.call
|
51
|
+
end
|
50
52
|
end
|
51
53
|
end
|
52
|
-
end
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
55
|
+
# nodoc:
|
56
|
+
class Message < Concurrent::ImmutableStruct.new(:target, :name, :args, :params, :block, :result)
|
57
|
+
def value(timeout: 30)
|
58
|
+
result.take(timeout)
|
59
|
+
end
|
60
|
+
alias_method :get, :value
|
61
|
+
alias_method :await, :value
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
def then &block
|
64
|
+
block&.call value
|
65
|
+
end
|
65
66
|
|
66
|
-
|
67
|
-
|
67
|
+
def call
|
68
|
+
result.put target.send(name, *args, **params, &block)
|
69
|
+
end
|
68
70
|
end
|
69
71
|
end
|
70
72
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: standard-procedure-async
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.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: 2023-
|
11
|
+
date: 2023-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
requirements: []
|
119
|
-
rubygems_version: 3.4.
|
119
|
+
rubygems_version: 3.4.22
|
120
120
|
signing_key:
|
121
121
|
specification_version: 4
|
122
122
|
summary: A simple wrapper around Concurrent::Future to make concurrent-ruby Rails-friendly.
|