async-conditions_list 0.1.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 +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +20 -0
- data/CHANGELOG.md +5 -0
- data/README.md +44 -0
- data/Rakefile +12 -0
- data/lib/async/conditions_list/version.rb +7 -0
- data/lib/async/conditions_list.rb +75 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 79c5d0704be97ff950af06e11d9f34e4178a8ad925790d3967aebb8d93a8efd9
|
4
|
+
data.tar.gz: 14105256b4ebf3ed9ce271ba8f35f3cd3931e5abb7451c80cdb19155c68511b6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b7d8ad945db5533c24dce48ab9b133776f140b3f490aaa8d1e89881f125bed99163f04787957506ebc77fa88df42b676aa45167580b0429013f67d97a1adc0f8
|
7
|
+
data.tar.gz: 4e001031e220493d5d261e9bd852e415b809b1843cc17643520097ce68c465d7d4749063b4d351a57c57819d83b3034999bf0e3aebfaa8cc7313ec40902e0083
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 3.1
|
3
|
+
|
4
|
+
Style/StringLiterals:
|
5
|
+
Enabled: true
|
6
|
+
EnforcedStyle: double_quotes
|
7
|
+
|
8
|
+
Style/StringLiteralsInInterpolation:
|
9
|
+
Enabled: true
|
10
|
+
EnforcedStyle: double_quotes
|
11
|
+
|
12
|
+
Layout/LineLength:
|
13
|
+
Max: 140
|
14
|
+
Exclude:
|
15
|
+
- spec/**/*
|
16
|
+
|
17
|
+
Metrics/BlockLength:
|
18
|
+
CountAsOne: ["array", "heredoc", "method_call"]
|
19
|
+
Exclude:
|
20
|
+
- spec/**/*
|
data/CHANGELOG.md
ADDED
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Async::ConditionsList
|
2
|
+
|
3
|
+
An extension to Async gem that allows to create a list of condition, wait for it and receive an array of results
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the gem and add to the application's Gemfile by executing:
|
8
|
+
|
9
|
+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
require 'async'
|
15
|
+
require 'async/conditions_list'
|
16
|
+
|
17
|
+
conditions_list = Async::ConditionsList.new(3)
|
18
|
+
|
19
|
+
Sync do |task|
|
20
|
+
task.async do
|
21
|
+
results = conditions_list.wait
|
22
|
+
p "All conditions have been met!"
|
23
|
+
p results
|
24
|
+
end
|
25
|
+
|
26
|
+
# Simulate asynchronous events
|
27
|
+
task.sleep(1)
|
28
|
+
conditions_list.signal(1)
|
29
|
+
task.sleep(1)
|
30
|
+
conditions_list.signal(2)
|
31
|
+
task.sleep(1)
|
32
|
+
conditions_list.signal(3)
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
## Development
|
37
|
+
|
38
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
39
|
+
|
40
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/holywalley/async-conditions_list.
|
data/Rakefile
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "conditions_list/version"
|
4
|
+
require "async"
|
5
|
+
|
6
|
+
module Async
|
7
|
+
# The ConditionsList class manages a collection of Async::Condition objects,
|
8
|
+
# allowing you to wait on multiple conditions and get accumulated result.
|
9
|
+
#
|
10
|
+
# == Initialization
|
11
|
+
#
|
12
|
+
# To create a new ConditionsList, specify the number of conditions you want to manage:
|
13
|
+
#
|
14
|
+
# conditions_list = Async::ConditionsList.new(size)
|
15
|
+
#
|
16
|
+
# == Methods
|
17
|
+
#
|
18
|
+
# - `wait`: Waits on all conditions in the list.
|
19
|
+
#
|
20
|
+
# - `signal(value = nil)`: Signals the current condition being waited on.
|
21
|
+
# If no condition has been waited on yet, it raises `ConditionsList::Error`.
|
22
|
+
#
|
23
|
+
# == Example Usage
|
24
|
+
#
|
25
|
+
# require 'async'
|
26
|
+
# require 'async/conditions_list'
|
27
|
+
#
|
28
|
+
# conditions_list = Async::ConditionsList.new(3)
|
29
|
+
#
|
30
|
+
# Sync do |task|
|
31
|
+
# task.async do
|
32
|
+
# conditions_list.wait
|
33
|
+
# puts "All conditions have been met!"
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# # Simulate asynchronous events
|
37
|
+
# task.sleep(1)
|
38
|
+
# conditions_list.signal
|
39
|
+
# task.sleep(1)
|
40
|
+
# conditions_list.signal
|
41
|
+
# task.sleep(1)
|
42
|
+
# conditions_list.signal
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
# == Error Handling
|
46
|
+
#
|
47
|
+
# - Raises `ConditionsList::Error` if `signal` is called before any condition has been waited on.
|
48
|
+
#
|
49
|
+
# == Notes
|
50
|
+
#
|
51
|
+
# - Ensure that the `wait` method is called before `signal` to avoid errors.
|
52
|
+
# - This class is intended to be used within the `Async` scheduler.
|
53
|
+
#
|
54
|
+
class ConditionsList
|
55
|
+
class Error < StandardError; end
|
56
|
+
|
57
|
+
def initialize(size)
|
58
|
+
@list = Array.new(size) { Async::Condition.new }
|
59
|
+
@current_condition = nil
|
60
|
+
end
|
61
|
+
|
62
|
+
def wait
|
63
|
+
@list.map do |condition|
|
64
|
+
@current_condition = condition
|
65
|
+
condition.wait
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def signal(value = nil)
|
70
|
+
raise Error, "No condition has been waited on yet." unless @current_condition
|
71
|
+
|
72
|
+
@current_condition.signal(value)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: async-conditions_list
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- HolyWalley
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-10-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: async
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.17'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.17'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- yakau@hey.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".rspec"
|
35
|
+
- ".rubocop.yml"
|
36
|
+
- CHANGELOG.md
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- lib/async/conditions_list.rb
|
40
|
+
- lib/async/conditions_list/version.rb
|
41
|
+
homepage: https://github.com/HolyWalley/async-conditions_list
|
42
|
+
licenses: []
|
43
|
+
metadata:
|
44
|
+
homepage_uri: https://github.com/HolyWalley/async-conditions_list
|
45
|
+
source_code_uri: https://github.com/HolyWalley/async-conditions_list
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.1.0
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubygems_version: 3.5.3
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: An extension to Async gem that allows to create a list of condition, wait
|
65
|
+
for it and receive an array of results
|
66
|
+
test_files: []
|