async-await 0.6.0 → 0.7.0

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: 60b68ca501e24b540ab2868d13331718fedce992928ed6ac3e29ae00caa3ef82
4
- data.tar.gz: 1e56657845f348d4c5657974a35c417176ddf5e63c595a8084e3fe0f7ff2f291
3
+ metadata.gz: bb18ada12c5c9f610552caf9497fea312501470bb22280bd5053d16cb1fc2e5d
4
+ data.tar.gz: 908a0ec28c62ee51fd8fbbb47513d4102553a9afd596cd4297c00654dd961f22
5
5
  SHA512:
6
- metadata.gz: 502521efb2e174c861cc324fbdb8c141e37c16ddd2c91664fd54e3b90d9e4a3bc103ef12a01b41deb4fed4d3997a2bce4820b14d9d10f3ea38f50b4b0b505810
7
- data.tar.gz: 231a2b125fa5f63260ea6cfb83f06c7beab995e35c868b7d87932b4105d43b31491287081d431ecdee9ef9a906d4b051dcf3c79a49d90826511fef2d22561b15
6
+ metadata.gz: ae3e7f82650b4ef2af5a392f5b5e22bc0eaec2a38b0de10bbd1e15d0c7dd56d711cc5c9584145adfbb5e30ca8834064ee905ba8b014e6383461706e19b6483f0
7
+ data.tar.gz: b154981442ff02d51337e201ff965eea85282c47c47d6065a09057e96c0b21b81a129a3a8ee5b9e8c753b55a8a514c1b80f7ad4d2763d148d2b00dd388f145c0
checksums.yaml.gz.sig ADDED
Binary file
@@ -1,38 +1,33 @@
1
- # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2020-2024, by Samuel Williams.
5
+
6
+ require 'async'
20
7
 
21
8
  module Async
22
9
  module Await
23
10
  module Enumerable
24
- def async_map(parent: Task.current, &block)
25
- self.map do |*arguments|
26
- parent.async do
27
- yield(*arguments)
28
- end
29
- end.map(&:wait)
11
+ def async_map(parent: nil, &block)
12
+ Sync do |task|
13
+ parent ||= task
14
+
15
+ self.map do |*arguments|
16
+ parent.async do
17
+ yield(*arguments)
18
+ end
19
+ end.map(&:wait)
20
+ end
30
21
  end
31
22
 
32
- def async_each(parent: Task.current, &block)
33
- self.each do |*arguments|
34
- parent.async do
35
- yield(*arguments)
23
+ def async_each(parent: nil, &block)
24
+ Sync do |task|
25
+ parent ||= task
26
+
27
+ self.each do |*arguments|
28
+ parent.async do
29
+ yield(*arguments)
30
+ end
36
31
  end
37
32
  end
38
33
 
@@ -42,10 +37,4 @@ module Async
42
37
  end
43
38
  end
44
39
 
45
- # ::Enumerable.include(Async::Await::Enumerable)
46
- # https://bugs.ruby-lang.org/issues/9573
47
- module Enumerable
48
- Async::Await::Enumerable.instance_methods.each do |name|
49
- self.define_method(name, Async::Await::Enumerable.instance_method(name))
50
- end
51
- end
40
+ ::Enumerable.include(Async::Await::Enumerable)
@@ -1,25 +1,10 @@
1
- # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2017-2024, by Samuel Williams.
20
5
 
21
6
  module Async
22
7
  module Await
23
- VERSION = "0.6.0"
8
+ VERSION = "0.7.0"
24
9
  end
25
10
  end
data/lib/async/await.rb CHANGED
@@ -1,32 +1,13 @@
1
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
1
+ # frozen_string_literal: true
20
2
 
21
- require_relative 'await/version'
22
- require_relative 'await/methods'
3
+ # Released under the MIT License.
4
+ # Copyright, 2017-2024, by Samuel Williams.
23
5
 
24
- require 'ruby2_keywords'
6
+ require_relative 'await/version'
25
7
 
26
8
  module Async
27
9
  module Await
28
10
  def self.included(klass)
29
- klass.include(Methods)
30
11
  klass.extend(self)
31
12
  end
32
13
 
@@ -44,8 +25,6 @@ module Async
44
25
  end.wait
45
26
  end
46
27
  end
47
-
48
- ruby2_keywords(name)
49
28
  end
50
29
 
51
30
  def async(name)
@@ -58,8 +37,6 @@ module Async
58
37
  original_method.bind(self).call(*arguments, &block)
59
38
  end
60
39
  end
61
-
62
- ruby2_keywords(name)
63
40
  end
64
41
  end
65
42
  end
data/license.md ADDED
@@ -0,0 +1,23 @@
1
+ # MIT License
2
+
3
+ Copyright, 2017-2024, by Samuel Williams.
4
+ Copyright, 2018, by Kent 'picat' Gruber.
5
+ Copyright, 2020, by Olle Jonsson.
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
data/readme.md ADDED
@@ -0,0 +1,61 @@
1
+ # Async::Await
2
+
3
+ Implements the async/await pattern for Ruby using [async](https://github.com/socketry/async).
4
+
5
+ [![Development Status](https://github.com/socketry/async-await/workflows/Test/badge.svg)](https://github.com/socketry/async-await/actions?workflow=Test)
6
+
7
+ ## Installation
8
+
9
+ ``` shell
10
+ bundle add async-await
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ In any asynchronous context (e.g. a reactor), simply use the `await` function like so:
16
+
17
+ ``` ruby
18
+ require 'async/await'
19
+
20
+ class Coop
21
+ include Async::Await
22
+
23
+ async def count_chickens(area_name)
24
+ 3.times do |i|
25
+ sleep rand
26
+
27
+ puts "Found a chicken in the #{area_name}!"
28
+ end
29
+ end
30
+
31
+ async def count_all_chickens
32
+ # These methods all run at the same time.
33
+ count_chickens("garden")
34
+ count_chickens("house")
35
+
36
+ # We wait for the result
37
+ count_chickens("tree").wait
38
+ end
39
+ end
40
+
41
+ coop = Coop.new
42
+ coop.count_all_chickens
43
+ ```
44
+
45
+ ## Contributing
46
+
47
+ We welcome contributions to this project.
48
+
49
+ 1. Fork it.
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`).
51
+ 3. Commit your changes (`git commit -am 'Add some feature'`).
52
+ 4. Push to the branch (`git push origin my-new-feature`).
53
+ 5. Create new Pull Request.
54
+
55
+ ### Developer Certificate of Origin
56
+
57
+ This project uses the [Developer Certificate of Origin](https://developercertificate.org/). All contributors to this project must agree to this document to have their contributions accepted.
58
+
59
+ ### Contributor Covenant
60
+
61
+ This project is governed by the [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
data.tar.gz.sig ADDED
Binary file
metadata CHANGED
@@ -1,14 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-await
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
+ - Kent 'picat' Gruber
9
+ - Olle Jonsson
8
10
  autorequire:
9
11
  bindir: bin
10
- cert_chain: []
11
- date: 2021-12-23 00:00:00.000000000 Z
12
+ cert_chain:
13
+ - |
14
+ -----BEGIN CERTIFICATE-----
15
+ MIIE2DCCA0CgAwIBAgIBATANBgkqhkiG9w0BAQsFADBhMRgwFgYDVQQDDA9zYW11
16
+ ZWwud2lsbGlhbXMxHTAbBgoJkiaJk/IsZAEZFg1vcmlvbnRyYW5zZmVyMRIwEAYK
17
+ CZImiZPyLGQBGRYCY28xEjAQBgoJkiaJk/IsZAEZFgJuejAeFw0yMjA4MDYwNDUz
18
+ MjRaFw0zMjA4MDMwNDUzMjRaMGExGDAWBgNVBAMMD3NhbXVlbC53aWxsaWFtczEd
19
+ MBsGCgmSJomT8ixkARkWDW9yaW9udHJhbnNmZXIxEjAQBgoJkiaJk/IsZAEZFgJj
20
+ bzESMBAGCgmSJomT8ixkARkWAm56MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIB
21
+ igKCAYEAomvSopQXQ24+9DBB6I6jxRI2auu3VVb4nOjmmHq7XWM4u3HL+pni63X2
22
+ 9qZdoq9xt7H+RPbwL28LDpDNflYQXoOhoVhQ37Pjn9YDjl8/4/9xa9+NUpl9XDIW
23
+ sGkaOY0eqsQm1pEWkH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hGc61JR6lvkGYQ2MYskBveyaxt
39
+ Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
40
+ voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
41
+ -----END CERTIFICATE-----
42
+ date: 2024-06-04 00:00:00.000000000 Z
12
43
  dependencies:
13
44
  - !ruby/object:Gem::Dependency
14
45
  name: async
@@ -24,62 +55,6 @@ dependencies:
24
55
  - - ">="
25
56
  - !ruby/object:Gem::Version
26
57
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: ruby2_keywords
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: async-rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.1'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.1'
55
- - !ruby/object:Gem::Dependency
56
- name: covered
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '3.0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '3.0'
83
58
  description:
84
59
  email:
85
60
  executables: []
@@ -88,12 +63,14 @@ extra_rdoc_files: []
88
63
  files:
89
64
  - lib/async/await.rb
90
65
  - lib/async/await/enumerable.rb
91
- - lib/async/await/methods.rb
92
66
  - lib/async/await/version.rb
67
+ - license.md
68
+ - readme.md
93
69
  homepage: https://github.com/socketry/async-await
94
70
  licenses:
95
71
  - MIT
96
- metadata: {}
72
+ metadata:
73
+ source_code_uri: https://github.com/socketry/async-await.git
97
74
  post_install_message:
98
75
  rdoc_options: []
99
76
  require_paths:
@@ -102,14 +79,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
79
  requirements:
103
80
  - - ">="
104
81
  - !ruby/object:Gem::Version
105
- version: '0'
82
+ version: '3.1'
106
83
  required_rubygems_version: !ruby/object:Gem::Requirement
107
84
  requirements:
108
85
  - - ">="
109
86
  - !ruby/object:Gem::Version
110
87
  version: '0'
111
88
  requirements: []
112
- rubygems_version: 3.3.0
89
+ rubygems_version: 3.5.3
113
90
  signing_key:
114
91
  specification_version: 4
115
92
  summary: Implements the async/await pattern on top of async :)
metadata.gz.sig ADDED
Binary file
@@ -1,43 +0,0 @@
1
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'async/reactor'
22
-
23
- module Async
24
- module Await
25
- module Methods
26
- extend Forwardable
27
-
28
- def task
29
- Async::Task.current
30
- end
31
-
32
- def_delegators :task, :with_timeout, :sleep, :async
33
-
34
- def await(&block)
35
- block.call.wait
36
- end
37
-
38
- def barrier!
39
- task.children.each(&:wait)
40
- end
41
- end
42
- end
43
- end