standard-procedure-async 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4936777d02c93a9195506f2807a9ecfbc80ccbfd4e50e9af6477456742efaf9a
4
- data.tar.gz: 1a094f5fbe3e205204a1425eeb798cdfd075b497d2e9afb4e64b132a040964f6
3
+ metadata.gz: 3aa258b93fc54c1232b652af7903b0fa85b4066aa09c442a4072c7d02d1fcf98
4
+ data.tar.gz: ef18826e86e742dcf96ac784dd654cbc9d07ce7aa71859fed83e58f488b87eca
5
5
  SHA512:
6
- metadata.gz: 9bacc126f5ecde4c54d9caf9d25cc73ccce1aa683d39ed4936ed4504791ab526af630511b4522c9fad7d699e55f5b8c9139a6d5e5b763fd0d550f386a4fafdf9
7
- data.tar.gz: 45aceadf0e436aee7da11a21f2958953caa5e6de88938faac63340384554da0afae44230629a184560ecf4c700d93dab6d7c9d88c4b63d71d97726be43398423
6
+ metadata.gz: 3c8168d2340e8e1ae2b5627f21c1f7a06adb0fb34845b4c1a4f0ba94e70fcd4609f2d502bd35441b0dd755ffc764a40e5ea69ae0949b20ddeb88a625bb8ea490
7
+ data.tar.gz: c0236a569b587399f419fed3b02b1991fd5d3bcbd286e514ee232f79a66e6b899b4ffbe798c622a5201c69896e1f8b8cb313c47bda2d74c75c9eaee81425a1e7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.2.1] - 2023-12-24
2
+
3
+ - Bugfix: allow keyword arguments
4
+
1
5
  ## [0.1.2] - 2023-05-31
2
6
 
3
7
  - Added a timeout to `StandardProcedure::Async::Actor::Message` to prevent indefinite deadlocks.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- standard-procedure-async (0.2.0)
4
+ standard-procedure-async (0.2.1)
5
5
  concurrent-ruby (>= 1.0)
6
6
 
7
7
  GEM
@@ -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::Async
8
- module Actor
9
- def self.included base
10
- base.class_eval do
11
- extend ClassMethods
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
- def initialize *args
14
- super
15
- @_messages = Concurrent::Array.new
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
- module ClassMethods
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
- define_method implementation_name do |*args, &block|
30
- implementation.call(*args, &block)
31
- end
32
+ def _messages
33
+ @_messages ||= Concurrent::Array.new
32
34
  end
33
- end
34
35
 
35
- private
36
-
37
- attr_reader :_messages
36
+ def _promises
37
+ @_promises ||= StandardProcedure::Async::Promises.new
38
+ end
38
39
 
39
- def _add_message_to_queue name, *args, &block
40
- message = Message.new(self, name, args, block, Concurrent::MVar.new)
41
- _messages << message
42
- _perform_messages if _messages.count == 1
43
- message
44
- end
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
- def _perform_messages
47
- StandardProcedure::Async.promises.future do
48
- while (message = _messages.shift)
49
- message.call
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
- # nodoc:
55
- class Message < Concurrent::ImmutableStruct.new(:target, :name, :args, :block, :result)
56
- def value(timeout: 30)
57
- result.take(timeout)
58
- end
59
- alias_method :get, :value
60
- alias_method :await, :value
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
- def then &block
63
- block&.call value
64
- end
63
+ def then &block
64
+ block&.call value
65
+ end
65
66
 
66
- def call
67
- result.put target.send(name, *args, &block)
67
+ def call
68
+ result.put target.send(name, *args, **params, &block)
69
+ end
68
70
  end
69
71
  end
70
72
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module StandardProcedure
4
4
  module Async
5
- VERSION = "0.2.0"
5
+ VERSION = "0.2.1"
6
6
  end
7
7
  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.0
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-10-13 00:00:00.000000000 Z
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.20
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.