async-await 0.7.0 → 0.8.0
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/async/await/enumerable.rb +13 -3
- data/lib/async/await/version.rb +1 -1
- data/lib/async/await.rb +15 -2
- data/license.md +1 -1
- data/readme.md +6 -38
- data.tar.gz.sig +0 -0
- metadata +4 -8
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d27b16c1a38a595f31ccfbe742c2d29712ac97b4b9c56ab64e6a793b0b52291f
|
4
|
+
data.tar.gz: fd996d7db069e959fc9572ac4ec58a931e99fdc41e5c543eb5caf1e94d16051d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b7a82fe11c667443425e3da84cf349a010a9bf598fffe85e00e72cfb4598e92f30cc0bebbb8ca76af7c441e64b2709ba2648aa16254c1de7d2cba4bd7c97f38
|
7
|
+
data.tar.gz: 699dccb7567f8b139d06661e117500989c55071c99c50724243d9e6a8e43e6c2eb70d6cbebd5c81428adfc51227c3d128a0888a1226ee04be166754fbc458a70
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -1,25 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2020-
|
4
|
+
# Copyright, 2020-2025, by Samuel Williams.
|
5
5
|
|
6
|
-
require
|
6
|
+
require "async"
|
7
7
|
|
8
8
|
module Async
|
9
9
|
module Await
|
10
|
+
# Provide asynchronous methods for enumerables.
|
10
11
|
module Enumerable
|
12
|
+
# This method is used to map the elements of an enumerable collection asynchronously.
|
13
|
+
#
|
14
|
+
# @parameter parent [Interface(:async)] The parent to use for creating new tasks.
|
15
|
+
# @yields {|item| ...} The block to execute for each element in the collection.
|
11
16
|
def async_map(parent: nil, &block)
|
12
17
|
Sync do |task|
|
13
18
|
parent ||= task
|
14
19
|
|
15
20
|
self.map do |*arguments|
|
16
|
-
parent.async do
|
21
|
+
parent.async(finished: false) do
|
17
22
|
yield(*arguments)
|
18
23
|
end
|
19
24
|
end.map(&:wait)
|
20
25
|
end
|
21
26
|
end
|
22
27
|
|
28
|
+
# This method is used to iterate over the elements of an enumerable collection asynchronously.
|
29
|
+
#
|
30
|
+
# @parameter parent [Interface(:async)] The parent to use for creating new tasks.
|
31
|
+
# @yields {|item| ...} The block to execute for each element in the collection.
|
32
|
+
# @return [self] The original enumerable collection.
|
23
33
|
def async_each(parent: nil, &block)
|
24
34
|
Sync do |task|
|
25
35
|
parent ||= task
|
data/lib/async/await/version.rb
CHANGED
data/lib/async/await.rb
CHANGED
@@ -1,16 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2017-
|
4
|
+
# Copyright, 2017-2025, by Samuel Williams.
|
5
5
|
|
6
|
-
require_relative
|
6
|
+
require_relative "await/version"
|
7
7
|
|
8
|
+
# @namespace
|
8
9
|
module Async
|
10
|
+
# Provide a way to wrap methods so that they can be run synchronously or asynchronously in an event loop.
|
9
11
|
module Await
|
12
|
+
# A hook that is called when the module is included in a class in order to provide the class with the methods defined in this module.
|
10
13
|
def self.included(klass)
|
11
14
|
klass.extend(self)
|
12
15
|
end
|
13
16
|
|
17
|
+
# Wrap the method with the given name in a block that will run the method synchronously in an event loop.
|
18
|
+
#
|
19
|
+
# @parameter name [Symbol] The name of the method to wrap.
|
14
20
|
def sync(name)
|
15
21
|
original_method = instance_method(name)
|
16
22
|
|
@@ -25,8 +31,13 @@ module Async
|
|
25
31
|
end.wait
|
26
32
|
end
|
27
33
|
end
|
34
|
+
|
35
|
+
return name
|
28
36
|
end
|
29
37
|
|
38
|
+
# Wrap the method with the given name in a block that will run the method asynchronously in an event loop.
|
39
|
+
#
|
40
|
+
# @parameter name [Symbol] The name of the method to wrap.
|
30
41
|
def async(name)
|
31
42
|
original_method = instance_method(name)
|
32
43
|
|
@@ -37,6 +48,8 @@ module Async
|
|
37
48
|
original_method.bind(self).call(*arguments, &block)
|
38
49
|
end
|
39
50
|
end
|
51
|
+
|
52
|
+
return name
|
40
53
|
end
|
41
54
|
end
|
42
55
|
end
|
data/license.md
CHANGED
data/readme.md
CHANGED
@@ -4,43 +4,11 @@ Implements the async/await pattern for Ruby using [async](https://github.com/soc
|
|
4
4
|
|
5
5
|
[](https://github.com/socketry/async-await/actions?workflow=Test)
|
6
6
|
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
``` shell
|
10
|
-
bundle add async-await
|
11
|
-
```
|
12
|
-
|
13
7
|
## Usage
|
14
8
|
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
```
|
9
|
+
Please see the [project documentation](https://socketry.github.io/async-await/) for more details.
|
10
|
+
|
11
|
+
- [Getting Started](https://socketry.github.io/async-await/guides/getting-started/index) - This guide explains how to use `async-await` for implementing some common concurrency patterns.
|
44
12
|
|
45
13
|
## Contributing
|
46
14
|
|
@@ -54,8 +22,8 @@ We welcome contributions to this project.
|
|
54
22
|
|
55
23
|
### Developer Certificate of Origin
|
56
24
|
|
57
|
-
|
25
|
+
In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed.
|
58
26
|
|
59
|
-
###
|
27
|
+
### Community Guidelines
|
60
28
|
|
61
|
-
This project is
|
29
|
+
This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async-await
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
- Kent 'picat' Gruber
|
9
9
|
- Olle Jonsson
|
10
|
-
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain:
|
13
12
|
- |
|
@@ -39,7 +38,7 @@ cert_chain:
|
|
39
38
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
40
39
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
41
40
|
-----END CERTIFICATE-----
|
42
|
-
date:
|
41
|
+
date: 2025-04-09 00:00:00.000000000 Z
|
43
42
|
dependencies:
|
44
43
|
- !ruby/object:Gem::Dependency
|
45
44
|
name: async
|
@@ -55,8 +54,6 @@ dependencies:
|
|
55
54
|
- - ">="
|
56
55
|
- !ruby/object:Gem::Version
|
57
56
|
version: '0'
|
58
|
-
description:
|
59
|
-
email:
|
60
57
|
executables: []
|
61
58
|
extensions: []
|
62
59
|
extra_rdoc_files: []
|
@@ -70,8 +67,8 @@ homepage: https://github.com/socketry/async-await
|
|
70
67
|
licenses:
|
71
68
|
- MIT
|
72
69
|
metadata:
|
70
|
+
documentation_uri: https://socketry.github.io/async-await/
|
73
71
|
source_code_uri: https://github.com/socketry/async-await.git
|
74
|
-
post_install_message:
|
75
72
|
rdoc_options: []
|
76
73
|
require_paths:
|
77
74
|
- lib
|
@@ -86,8 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
83
|
- !ruby/object:Gem::Version
|
87
84
|
version: '0'
|
88
85
|
requirements: []
|
89
|
-
rubygems_version: 3.
|
90
|
-
signing_key:
|
86
|
+
rubygems_version: 3.6.2
|
91
87
|
specification_version: 4
|
92
88
|
summary: Implements the async/await pattern on top of async :)
|
93
89
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|