standard-procedure-async 0.2.0 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4936777d02c93a9195506f2807a9ecfbc80ccbfd4e50e9af6477456742efaf9a
4
- data.tar.gz: 1a094f5fbe3e205204a1425eeb798cdfd075b497d2e9afb4e64b132a040964f6
3
+ metadata.gz: ae90def8fcf35af35510635da2d65e967ae4233ea7fff7b8b9b5192efe681f0c
4
+ data.tar.gz: c19084657be08e00c3383f4dd67f36b1f53be2637a7af868f955369b169069c6
5
5
  SHA512:
6
- metadata.gz: 9bacc126f5ecde4c54d9caf9d25cc73ccce1aa683d39ed4936ed4504791ab526af630511b4522c9fad7d699e55f5b8c9139a6d5e5b763fd0d550f386a4fafdf9
7
- data.tar.gz: 45aceadf0e436aee7da11a21f2958953caa5e6de88938faac63340384554da0afae44230629a184560ecf4c700d93dab6d7c9d88c4b63d71d97726be43398423
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
@@ -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,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::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).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
- def then &block
63
- block&.call value
64
- end
65
+ def then &block
66
+ block&.call value
67
+ end
65
68
 
66
- def call
67
- result.put target.send(name, *args, &block)
69
+ def call
70
+ result.put target.send(name, *args, **params, &block)
71
+ end
68
72
  end
69
73
  end
70
74
  end
@@ -1,5 +1,7 @@
1
1
  module Kernel
2
2
  def await &block
3
- block.call.value
3
+ block.call.value.tap do |result|
4
+ raise result if result.is_a? Exception
5
+ end
4
6
  end
5
7
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module StandardProcedure
4
4
  module Async
5
- VERSION = "0.2.0"
5
+ VERSION = "0.2.2"
6
6
  end
7
7
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "lib/standard_procedure/async/version"
3
+ require_relative "lib/standard_procedure/async"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "standard-procedure-async"
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.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: 2023-10-13 00:00:00.000000000 Z
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.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.