standard-procedure-async 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +1 -1
- data/lib/standard_procedure/async/actor.rb +51 -47
- data/lib/standard_procedure/async/await.rb +3 -1
- data/lib/standard_procedure/async/version.rb +1 -1
- data/standard-procedure-async.gemspec +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: ae90def8fcf35af35510635da2d65e967ae4233ea7fff7b8b9b5192efe681f0c
|
4
|
+
data.tar.gz: c19084657be08e00c3383f4dd67f36b1f53be2637a7af868f955369b169069c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24457a850f4bd6d67ebf0e221ffe7001fbcd2f383f4b151678a2e8fd64974a3c7078781419a11fab8239d3b762ca0c0a235864c788418c14f1336a028717e697
|
7
|
+
data.tar.gz: 217185e538e930352f32ba24cd4f88445733ff9b85f9501d1f702706ec8f9b9a4f4cd4088627a577ee77d9548bed5732fba1573c6c651307d24554204fc3e7db
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## [0.2.2] - 2024-01-30
|
2
|
+
|
3
|
+
- raises an exception if the asynchronous method return an exception
|
4
|
+
|
5
|
+
## [0.2.1] - 2023-12-24
|
6
|
+
|
7
|
+
- Bugfix: allow keyword arguments
|
8
|
+
|
1
9
|
## [0.1.2] - 2023-05-31
|
2
10
|
|
3
11
|
- Added a timeout to `StandardProcedure::Async::Actor::Message` to prevent indefinite deadlocks.
|
data/Gemfile.lock
CHANGED
@@ -3,68 +3,72 @@
|
|
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).tap do |value|
|
59
|
+
raise value if value.is_a? Exception
|
60
|
+
end
|
61
|
+
end
|
62
|
+
alias_method :get, :value
|
63
|
+
alias_method :await, :value
|
61
64
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
+
def then &block
|
66
|
+
block&.call value
|
67
|
+
end
|
65
68
|
|
66
|
-
|
67
|
-
|
69
|
+
def call
|
70
|
+
result.put target.send(name, *args, **params, &block)
|
71
|
+
end
|
68
72
|
end
|
69
73
|
end
|
70
74
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rahoul Baruah
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-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.
|