async 1.22.1 → 1.22.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: 54242c72b2d813b19ca5720e42810fed147dc8b287a541d937b4b5b269d21853
4
- data.tar.gz: 994b539a0c57f1d88dc9fbe1337f6d7757d042e92b617bff6078b253dced5194
3
+ metadata.gz: 61d9644a199a84c93e9b9212c31e210343aebd41af6fd62647d600c72658248d
4
+ data.tar.gz: a275b10657182f96c8ce5578321774b4def1c50374cf0f602387e1a2312e8c36
5
5
  SHA512:
6
- metadata.gz: 5e4b6ac679779d60c72a379534ac3b83adb1e9c8633afcc3aba4679cc5f6d4491572fde39ab663cc170ae47db33b1cfbbe1a7e3611be87427224372c65853629
7
- data.tar.gz: 863fc5ed61d8380698ab6ed48d6b7f738708bb408157d6de4d4cd58b36d3022db91dfa6e295e5eb547e71bbce17867767adc1467f5ca966bd13cf4a078aabc07
6
+ metadata.gz: 4c6d818ec258c64b8d1d2f46bb90360024d114829110a8f4bce27ec740b6d33781b8b5a11a622e28a680a212a91f5550b94ecd34ee3e8e0624937bb290757d8a
7
+ data.tar.gz: c530521f3102302be5127d3b46a50162682a07beb632c21a281776d33a1b36a15ffc40042d05584c6d36fd8be2732f3ab364bf4149f2a27cc623a541d40c6580
@@ -0,0 +1,38 @@
1
+ name: Tests
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+ strategy:
8
+ matrix:
9
+ os:
10
+ - ubuntu
11
+ # - macos
12
+
13
+ ruby:
14
+ - 2.3
15
+ - 2.4
16
+ - 2.5
17
+ - 2.6
18
+
19
+ include:
20
+ - os: 'ubuntu'
21
+ ruby: '2.6'
22
+ env: COVERAGE=PartialSummary,Coveralls
23
+
24
+ runs-on: ${{matrix.os}}-latest
25
+
26
+ steps:
27
+ - uses: actions/checkout@v1
28
+ - uses: actions/setup-ruby@v1
29
+ with:
30
+ ruby-version: ${{matrix.ruby}}
31
+ - name: Install dependencies
32
+ run: |
33
+ gem install bundler
34
+ bundle install
35
+ - name: Run tests
36
+ run: ${{matrix.env}} bundle exec rspec
37
+ - name: Run external tests
38
+ run: bundle exec rake external
@@ -30,12 +30,16 @@ module Async
30
30
  # All tasks which have been invoked into the barrier.
31
31
  attr :tasks
32
32
 
33
- def async(*args, task: Task.current, **options, &block)
34
- subtask = task.async(*args, **options, &block)
33
+ def size
34
+ @tasks.size
35
+ end
36
+
37
+ def async(*args, parent: Task.current, **options, &block)
38
+ task = parent.async(*args, **options, &block)
35
39
 
36
- @tasks << subtask
40
+ @tasks << task
37
41
 
38
- return subtask
42
+ return task
39
43
  end
40
44
 
41
45
  def empty?
@@ -47,14 +47,14 @@ module Async
47
47
  end
48
48
 
49
49
  # Run an async task. Will wait until the semaphore is ready until spawning and running the task.
50
- def async(*args, task: Task.current, **options)
50
+ def async(*args, parent: Task.current, **options)
51
51
  wait
52
52
 
53
- task.async(**options) do |subtask|
53
+ parent.async(**options) do |task|
54
54
  @count += 1
55
55
 
56
56
  begin
57
- yield subtask, *args
57
+ yield task, *args
58
58
  ensure
59
59
  self.release
60
60
  end
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Async
22
- VERSION = "1.22.1"
22
+ VERSION = "1.22.2"
23
23
  end
@@ -22,6 +22,8 @@ require 'async/barrier'
22
22
  require 'async/clock'
23
23
  require 'async/rspec'
24
24
 
25
+ require 'async/semaphore'
26
+
25
27
  RSpec.describe Async::Barrier do
26
28
  include_context Async::RSpec::Reactor
27
29
 
@@ -74,4 +76,21 @@ RSpec.describe Async::Barrier do
74
76
  expect(subject).to be_empty
75
77
  end
76
78
  end
79
+
80
+ context 'with semaphore' do
81
+ let(:capacity) {2}
82
+ let(:semaphore) {Async::Semaphore.new(capacity)}
83
+ let(:repeats) {capacity * 2}
84
+
85
+ it 'should execute several tasks and wait using a barrier' do
86
+ repeats.times do
87
+ subject.async(parent: semaphore) do |task|
88
+ task.sleep 0.1
89
+ end
90
+ end
91
+
92
+ expect(subject.size).to be == repeats
93
+ subject.wait
94
+ end
95
+ end
77
96
  end
@@ -19,6 +19,7 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  require 'async/semaphore'
22
+ require 'async/barrier'
22
23
  require 'async/rspec'
23
24
 
24
25
  RSpec.describe Async::Semaphore do
@@ -142,4 +143,21 @@ RSpec.describe Async::Semaphore do
142
143
  expect(subject.count).to be == 0
143
144
  end
144
145
  end
146
+
147
+ context 'with barrier' do
148
+ let(:capacity) {2}
149
+ let(:barrier) {Async::Barrier.new}
150
+ let(:repeats) {capacity * 2}
151
+
152
+ it 'should execute several tasks and wait using a barrier' do
153
+ repeats.times do
154
+ subject.async(parent: barrier) do |task|
155
+ task.sleep 0.1
156
+ end
157
+ end
158
+
159
+ expect(barrier.size).to be == repeats
160
+ barrier.wait
161
+ end
162
+ end
145
163
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.22.1
4
+ version: 1.22.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-09 00:00:00.000000000 Z
11
+ date: 2019-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nio4r
@@ -133,6 +133,7 @@ extra_rdoc_files: []
133
133
  files:
134
134
  - ".editorconfig"
135
135
  - ".github/FUNDING.yml"
136
+ - ".github/workflows/tests.yml"
136
137
  - ".gitignore"
137
138
  - ".rspec"
138
139
  - ".travis.yml"