async 2.21.1 → 2.21.2

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: 6dda1de8f976c85bf6dcbd0156c27c30f85f88d5ffaf32f3397b9838aa920bab
4
- data.tar.gz: 0f09cde08880db4456bc03e9a4351903b9a96ca7099e7305c76fdee7f8edc0ed
3
+ metadata.gz: '0821852f6bb8e8b82506934a6ad8e921270f121636453303a2fd6409cacd83e2'
4
+ data.tar.gz: 56992a10ff23bcba8dfa535f7c134ac2870a10dd62f7776ea9e109d5e14e0b05
5
5
  SHA512:
6
- metadata.gz: 980cd5e5832ddd71846785e10b23d18d11cb1f0eee33ccbdf33ed40feb4ac51dd99f7cf3d7f93055d0ad52de2abe0103c1b433d41f5bac1728c04435e35655db
7
- data.tar.gz: d9c7c1c69e49acd89738f44900502bc83aea08341b84a9f8d9e02588261889a24a935dfa6509394514a575a4b17d8dcf0ca512518e8b0e089369a8fd37b44d52
6
+ metadata.gz: 17791af587852dbb46ab3cb6b5584c10d7073997d1ba21eabed248fe1dc6a9107902ac34cf8741efacdfa01e87d57aa515f22635310fa35697ee56acd5cd03ee
7
+ data.tar.gz: e0a7fc1d5cd13632ceaa93e9ccb41ff89ec38648d8ca6d5eb2831ea39cb014d2fb8046c3226d94d7101a5d289cecaff338fcf65c440627ae76cdd44a93e624a6
checksums.yaml.gz.sig CHANGED
Binary file
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2024, by Samuel Williams.
5
+
6
+ # The implementation lives in `queue.rb` but later we may move it here for better autoload/inference.
7
+ require_relative "queue"
data/lib/async/queue.rb CHANGED
@@ -45,7 +45,9 @@ module Async
45
45
  end
46
46
 
47
47
  # Compatibility with {::Queue#push}.
48
- alias << push
48
+ def <<(item)
49
+ self.push(item)
50
+ end
49
51
 
50
52
  # Add multiple items to the queue.
51
53
  def enqueue(*items)
@@ -64,7 +66,9 @@ module Async
64
66
  end
65
67
 
66
68
  # Compatibility with {::Queue#pop}.
67
- alias pop dequeue
69
+ def pop
70
+ self.dequeue
71
+ end
68
72
 
69
73
  # Process each item in the queue.
70
74
  #
@@ -125,7 +129,7 @@ module Async
125
129
  # If the queue is full, this method will block until there is space available.
126
130
  #
127
131
  # @parameter item [Object] The item to add to the queue.
128
- def <<(item)
132
+ def push(item)
129
133
  while limited?
130
134
  @full.wait
131
135
  end
data/lib/async/task.rb CHANGED
@@ -181,7 +181,10 @@ module Async
181
181
  @status == :completed
182
182
  end
183
183
 
184
- alias complete? completed?
184
+ # Alias for {#completed?}.
185
+ def complete?
186
+ self.completed?
187
+ end
185
188
 
186
189
  # @attribute [Symbol] The status of the execution of the task, one of `:initialized`, `:running`, `:complete`, `:stopped` or `:failed`.
187
190
  attr :status
@@ -31,7 +31,10 @@ module Async
31
31
  condition.signal(value)
32
32
  end
33
33
 
34
- alias value= resolve
34
+ # Alias for {#resolve}.
35
+ def value=(value)
36
+ self.resolve(value)
37
+ end
35
38
 
36
39
  # Whether the value has been resolved.
37
40
  #
@@ -48,6 +51,9 @@ module Async
48
51
  return @value
49
52
  end
50
53
 
51
- alias value wait
54
+ # Alias for {#wait}.
55
+ def value
56
+ self.wait
57
+ end
52
58
  end
53
59
  end
data/lib/async/version.rb CHANGED
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2017-2024, by Samuel Williams.
5
5
 
6
6
  module Async
7
- VERSION = "2.21.1"
7
+ VERSION = "2.21.2"
8
8
  end
@@ -10,6 +10,7 @@ module Async
10
10
  #
11
11
  # @private
12
12
  class WorkerPool
13
+ # Used to augment the scheduler to add support for blocking operations.
13
14
  module BlockingOperationWait
14
15
  # Wait for the given work to be executed.
15
16
  #
@@ -23,7 +24,11 @@ module Async
23
24
  end
24
25
  end
25
26
 
27
+ # Execute the given work in a background thread.
26
28
  class Promise
29
+ # Create a new promise.
30
+ #
31
+ # @parameter work [Proc] The work to be done.
27
32
  def initialize(work)
28
33
  @work = work
29
34
  @state = :pending
@@ -33,6 +38,7 @@ module Async
33
38
  @thread = nil
34
39
  end
35
40
 
41
+ # Execute the work and resolve the promise.
36
42
  def call
37
43
  work = nil
38
44
 
@@ -67,6 +73,7 @@ module Async
67
73
  end
68
74
  end
69
75
 
76
+ # Cancel the work and raise an exception in the background thread.
70
77
  def cancel
71
78
  return unless @work
72
79
 
@@ -77,6 +84,9 @@ module Async
77
84
  end
78
85
  end
79
86
 
87
+ # Wait for the work to be done.
88
+ #
89
+ # @returns [Object] The result of the work.
80
90
  def wait
81
91
  @guard.synchronize do
82
92
  while @state == :pending
@@ -92,19 +102,22 @@ module Async
92
102
  end
93
103
  end
94
104
 
95
- # A handle to the work being done.
105
+ # A background worker thread.
96
106
  class Worker
107
+ # Create a new worker.
97
108
  def initialize
98
109
  @work = ::Thread::Queue.new
99
110
  @thread = ::Thread.new(&method(:run))
100
111
  end
101
112
 
113
+ # Execute work until the queue is closed.
102
114
  def run
103
115
  while work = @work.pop
104
116
  work.call
105
117
  end
106
118
  end
107
119
 
120
+ # Close the worker thread.
108
121
  def close
109
122
  if thread = @thread
110
123
  @thread = nil
@@ -12,13 +12,17 @@ Traces::Provider(Async::Task) do
12
12
  trace_context = Traces.trace_context
13
13
  end
14
14
 
15
+ attributes = {
16
+ # We use the instance variable as it corresponds to the user-provided block.
17
+ "block" => @block,
18
+ "transient" => self.transient?,
19
+ }
20
+
15
21
  super do
16
22
  Traces.trace_context = trace_context
17
23
 
18
24
  if annotation = self.annotation
19
- attributes = {
20
- "annotation" => annotation
21
- }
25
+ attributes["annotation"] = annotation
22
26
  end
23
27
 
24
28
  Traces.trace("async.task", attributes: attributes) do
data/readme.md CHANGED
@@ -7,6 +7,7 @@ Async is a composable asynchronous I/O framework for Ruby based on [io-event](ht
7
7
  > beautifully designed." *– [janko](https://github.com/janko)*
8
8
 
9
9
  [![Development Status](https://github.com/socketry/async/workflows/Test/badge.svg)](https://github.com/socketry/async/actions?workflow=Test)
10
+ [<img src="https://api.gitsponsors.com/api/badge/img?id=87380483" height="20"/>](https://api.gitsponsors.com/api/badge/link?p=U4gCxvzG7eUksiJSe0MSlPHWWhBYryqj6i48tx5L7/r/2NgkAToKb6dEm31bAftU3H+7BVwk3VhUBtE4GHqHJTPfWPR6xo2BQVoT15rFAGAsLFgdT2kKopIfCGV/QDOm7BrkodS2//R7NUMksAdaCQ==)
10
11
 
11
12
  ## Features
12
13
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.21.1
4
+ version: 2.21.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -31,7 +31,6 @@ authors:
31
31
  - Sokolov Yura
32
32
  - Stefan Wrobel
33
33
  - Trevor Turk
34
- autorequire:
35
34
  bindir: bin
36
35
  cert_chain:
37
36
  - |
@@ -63,7 +62,7 @@ cert_chain:
63
62
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
64
63
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
65
64
  -----END CERTIFICATE-----
66
- date: 2024-11-27 00:00:00.000000000 Z
65
+ date: 2025-01-30 00:00:00.000000000 Z
67
66
  dependencies:
68
67
  - !ruby/object:Gem::Dependency
69
68
  name: console
@@ -113,8 +112,6 @@ dependencies:
113
112
  - - ">="
114
113
  - !ruby/object:Gem::Version
115
114
  version: 1.6.5
116
- description:
117
- email:
118
115
  executables: []
119
116
  extensions: []
120
117
  extra_rdoc_files: []
@@ -127,6 +124,7 @@ files:
127
124
  - lib/async/condition.rb
128
125
  - lib/async/console.rb
129
126
  - lib/async/idler.rb
127
+ - lib/async/limited_queue.rb
130
128
  - lib/async/list.rb
131
129
  - lib/async/node.rb
132
130
  - lib/async/notification.rb
@@ -160,7 +158,6 @@ metadata:
160
158
  documentation_uri: https://socketry.github.io/async/
161
159
  funding_uri: https://github.com/sponsors/ioquatix/
162
160
  source_code_uri: https://github.com/socketry/async.git
163
- post_install_message:
164
161
  rdoc_options: []
165
162
  require_paths:
166
163
  - lib
@@ -175,8 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
172
  - !ruby/object:Gem::Version
176
173
  version: '0'
177
174
  requirements: []
178
- rubygems_version: 3.5.22
179
- signing_key:
175
+ rubygems_version: 3.6.2
180
176
  specification_version: 4
181
177
  summary: A concurrency framework for Ruby.
182
178
  test_files: []
metadata.gz.sig CHANGED
Binary file