async 1.11.0 → 1.12.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
- data/.travis.yml +3 -5
- data/async.gemspec +1 -1
- data/lib/async/notification.rb +1 -1
- data/lib/async/queue.rb +30 -0
- data/lib/async/version.rb +1 -1
- data/spec/async/queue_spec.rb +19 -3
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40cffda648844d0b0a3ec212b9038bb0a211ed98675a9265336af674684ca5a6
|
4
|
+
data.tar.gz: b903703231b783e04911f5ea3df63774524fc4248a0c61d3f3a50a74881b4825
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5dc2640c9bc451b0a4d43b6a3a54769f564ed139492f18d8350d9e800257d13ac75b2dc321e7b3f9e5d95752e6caab8f7c9b0c593c3cebe590c0eea805b0697a
|
7
|
+
data.tar.gz: 3a408f2188b5d2c8ae42267aee14a63aa3e6cff08128a879551506b79de861243d8f5c7200f47a22990a12f99d9a97a61b4194c7770d03c89c9a0191f0cc7f81
|
data/.travis.yml
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
language: ruby
|
2
|
-
|
3
|
-
dist: trusty
|
2
|
+
dist: xenial
|
4
3
|
cache: bundler
|
4
|
+
|
5
5
|
addons:
|
6
6
|
apt:
|
7
7
|
packages:
|
8
8
|
- bind9
|
9
9
|
|
10
|
-
before_script:
|
10
|
+
before_script:
|
11
11
|
- sudo sh -c 'echo 0 > /proc/sys/net/ipv6/conf/all/disable_ipv6'
|
12
|
-
- gem update --system
|
13
|
-
- gem install bundler
|
14
12
|
|
15
13
|
matrix:
|
16
14
|
include:
|
data/async.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
|
28
28
|
spec.add_development_dependency "async-rspec", "~> 1.1"
|
29
29
|
|
30
|
-
spec.add_development_dependency "bundler"
|
30
|
+
spec.add_development_dependency "bundler"
|
31
31
|
spec.add_development_dependency "rspec", "~> 3.6"
|
32
32
|
spec.add_development_dependency "rake"
|
33
33
|
end
|
data/lib/async/notification.rb
CHANGED
@@ -21,7 +21,7 @@
|
|
21
21
|
require_relative 'condition'
|
22
22
|
|
23
23
|
module Async
|
24
|
-
# A synchronization
|
24
|
+
# A synchronization primitive, which allows fibers to wait until a notification is received. Does not block the task which signals the notification. Waiting tasks are resumed on next iteration of the reactor.
|
25
25
|
class Notification < Condition
|
26
26
|
# Signal to a given task that it should resume operations.
|
27
27
|
# @return [void]
|
data/lib/async/queue.rb
CHANGED
@@ -45,4 +45,34 @@ module Async
|
|
45
45
|
@items.shift
|
46
46
|
end
|
47
47
|
end
|
48
|
+
|
49
|
+
class LimitedQueue < Queue
|
50
|
+
def initialize(limit = 1)
|
51
|
+
super()
|
52
|
+
|
53
|
+
@limit = limit
|
54
|
+
@full = Async::Condition.new
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [Boolean] Whether trying to enqueue an item would block.
|
58
|
+
def limited?
|
59
|
+
@items.size >= @limit
|
60
|
+
end
|
61
|
+
|
62
|
+
def enqueue item
|
63
|
+
if limited?
|
64
|
+
@full.wait
|
65
|
+
end
|
66
|
+
|
67
|
+
super
|
68
|
+
end
|
69
|
+
|
70
|
+
def dequeue
|
71
|
+
item = super
|
72
|
+
|
73
|
+
@full.signal unless @full.empty?
|
74
|
+
|
75
|
+
return item
|
76
|
+
end
|
77
|
+
end
|
48
78
|
end
|
data/lib/async/version.rb
CHANGED
data/spec/async/queue_spec.rb
CHANGED
@@ -22,9 +22,7 @@ require 'async/queue'
|
|
22
22
|
|
23
23
|
require_relative 'condition_examples'
|
24
24
|
|
25
|
-
RSpec.
|
26
|
-
include_context Async::RSpec::Reactor
|
27
|
-
|
25
|
+
RSpec.shared_context Async::Queue do
|
28
26
|
it 'should process items in order' do
|
29
27
|
reactor.async do |task|
|
30
28
|
10.times do |i|
|
@@ -38,3 +36,21 @@ RSpec.describe Async::Queue do
|
|
38
36
|
end
|
39
37
|
end
|
40
38
|
end
|
39
|
+
|
40
|
+
RSpec.describe Async::Queue do
|
41
|
+
include_context Async::RSpec::Reactor
|
42
|
+
|
43
|
+
it_behaves_like Async::Queue
|
44
|
+
end
|
45
|
+
|
46
|
+
RSpec.describe Async::LimitedQueue do
|
47
|
+
include_context Async::RSpec::Reactor
|
48
|
+
|
49
|
+
it_behaves_like Async::Queue
|
50
|
+
|
51
|
+
it 'should become limited' do
|
52
|
+
expect(subject).to_not be_limited
|
53
|
+
subject.enqueue(10)
|
54
|
+
expect(subject).to be_limited
|
55
|
+
end
|
56
|
+
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.
|
4
|
+
version: 1.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nio4r
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -171,8 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
171
|
- !ruby/object:Gem::Version
|
172
172
|
version: '0'
|
173
173
|
requirements: []
|
174
|
-
|
175
|
-
rubygems_version: 2.7.7
|
174
|
+
rubygems_version: 3.0.0.beta3
|
176
175
|
signing_key:
|
177
176
|
specification_version: 4
|
178
177
|
summary: Async is an asynchronous I/O framework based on nio4r.
|