queue_ding 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/.semver +5 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +109 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +77 -0
- data/Rakefile +60 -0
- data/lib/queue_ding/queue_ding.rb +68 -0
- data/lib/queue_ding.rb +1 -0
- data/queue_ding.gemspec +78 -0
- data/spec/queue_ding_spec.rb +51 -0
- data/spec/spec_helper.rb +29 -0
- metadata +186 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d6bafcce8d888e90a2e18c0511bdc3e7cdd67b0b
|
4
|
+
data.tar.gz: 7b540a6f5300c9f11ece815865cffe02b730a57d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a6ea0aa085a40ac46e546f9401f8af5d1a3dd9019acc7b1e5533cf3bbb0e221ad87d491b0e64ea3230a0288e1ca31749262042a0f94f6ea1382086c9ce63910b
|
7
|
+
data.tar.gz: 19a8bc9e79b6370fb43dbbcc73bce935814729ab5c49e2271cdba59e1de15d3f40b11fe7a47b047ece245a15e96b59033bdb3bb004f1314bb446350febb330fb
|
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.semver
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem 'aquarium', '~> 0'
|
4
|
+
|
5
|
+
# Add dependencies to develop your gem here.
|
6
|
+
# Include everything needed to run rake, tests, features, etc.
|
7
|
+
group :development do
|
8
|
+
gem "rspec", "~> 2"
|
9
|
+
gem "yard", "~> 0"
|
10
|
+
gem "rdoc", "~> 3"
|
11
|
+
gem "bundler", "~> 1"
|
12
|
+
gem "jeweler", "~> 2"
|
13
|
+
gem "simplecov", "~> 0"
|
14
|
+
gem 'semver', '~> 1'
|
15
|
+
gem 'guard-rspec', '~> 0'
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.3.6)
|
5
|
+
aquarium (0.5.1)
|
6
|
+
builder (3.2.2)
|
7
|
+
celluloid (0.15.2)
|
8
|
+
timers (~> 1.1.0)
|
9
|
+
coderay (1.1.0)
|
10
|
+
descendants_tracker (0.0.4)
|
11
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
12
|
+
diff-lcs (1.2.5)
|
13
|
+
docile (1.1.5)
|
14
|
+
faraday (0.9.0)
|
15
|
+
multipart-post (>= 1.2, < 3)
|
16
|
+
ffi (1.9.3)
|
17
|
+
formatador (0.2.5)
|
18
|
+
git (1.2.7)
|
19
|
+
github_api (0.11.3)
|
20
|
+
addressable (~> 2.3)
|
21
|
+
descendants_tracker (~> 0.0.1)
|
22
|
+
faraday (~> 0.8, < 0.10)
|
23
|
+
hashie (>= 1.2)
|
24
|
+
multi_json (>= 1.7.5, < 2.0)
|
25
|
+
nokogiri (~> 1.6.0)
|
26
|
+
oauth2
|
27
|
+
guard (2.6.1)
|
28
|
+
formatador (>= 0.2.4)
|
29
|
+
listen (~> 2.7)
|
30
|
+
lumberjack (~> 1.0)
|
31
|
+
pry (>= 0.9.12)
|
32
|
+
thor (>= 0.18.1)
|
33
|
+
guard-rspec (0.7.3)
|
34
|
+
guard (>= 0.10.0)
|
35
|
+
hashie (3.2.0)
|
36
|
+
highline (1.6.21)
|
37
|
+
jeweler (2.0.1)
|
38
|
+
builder
|
39
|
+
bundler (>= 1.0)
|
40
|
+
git (>= 1.2.5)
|
41
|
+
github_api
|
42
|
+
highline (>= 1.6.15)
|
43
|
+
nokogiri (>= 1.5.10)
|
44
|
+
rake
|
45
|
+
rdoc
|
46
|
+
json (1.8.1)
|
47
|
+
jwt (1.0.0)
|
48
|
+
listen (2.7.9)
|
49
|
+
celluloid (>= 0.15.2)
|
50
|
+
rb-fsevent (>= 0.9.3)
|
51
|
+
rb-inotify (>= 0.9)
|
52
|
+
lumberjack (1.0.9)
|
53
|
+
method_source (0.8.2)
|
54
|
+
mini_portile (0.6.0)
|
55
|
+
multi_json (1.10.1)
|
56
|
+
multi_xml (0.5.5)
|
57
|
+
multipart-post (2.0.0)
|
58
|
+
nokogiri (1.6.2.1)
|
59
|
+
mini_portile (= 0.6.0)
|
60
|
+
oauth2 (1.0.0)
|
61
|
+
faraday (>= 0.8, < 0.10)
|
62
|
+
jwt (~> 1.0)
|
63
|
+
multi_json (~> 1.3)
|
64
|
+
multi_xml (~> 0.5)
|
65
|
+
rack (~> 1.2)
|
66
|
+
pry (0.10.0)
|
67
|
+
coderay (~> 1.1.0)
|
68
|
+
method_source (~> 0.8.1)
|
69
|
+
slop (~> 3.4)
|
70
|
+
rack (1.5.2)
|
71
|
+
rake (10.3.2)
|
72
|
+
rb-fsevent (0.9.4)
|
73
|
+
rb-inotify (0.9.5)
|
74
|
+
ffi (>= 0.5.0)
|
75
|
+
rdoc (3.12.2)
|
76
|
+
json (~> 1.4)
|
77
|
+
rspec (2.99.0)
|
78
|
+
rspec-core (~> 2.99.0)
|
79
|
+
rspec-expectations (~> 2.99.0)
|
80
|
+
rspec-mocks (~> 2.99.0)
|
81
|
+
rspec-core (2.99.1)
|
82
|
+
rspec-expectations (2.99.1)
|
83
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
84
|
+
rspec-mocks (2.99.1)
|
85
|
+
semver (1.0.1)
|
86
|
+
simplecov (0.9.0)
|
87
|
+
docile (~> 1.1.0)
|
88
|
+
multi_json
|
89
|
+
simplecov-html (~> 0.8.0)
|
90
|
+
simplecov-html (0.8.0)
|
91
|
+
slop (3.6.0)
|
92
|
+
thor (0.19.1)
|
93
|
+
thread_safe (0.3.4)
|
94
|
+
timers (1.1.0)
|
95
|
+
yard (0.8.7.4)
|
96
|
+
|
97
|
+
PLATFORMS
|
98
|
+
ruby
|
99
|
+
|
100
|
+
DEPENDENCIES
|
101
|
+
aquarium (~> 0)
|
102
|
+
bundler (~> 1)
|
103
|
+
guard-rspec (~> 0)
|
104
|
+
jeweler (~> 2)
|
105
|
+
rdoc (~> 3)
|
106
|
+
rspec (~> 2)
|
107
|
+
semver (~> 1)
|
108
|
+
simplecov (~> 0)
|
109
|
+
yard (~> 0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Fred Mitchell
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
= QueueDing alternative to Queue
|
2
|
+
|
3
|
+
This roughly mirrors the functionaly of Queue in allowing you to
|
4
|
+
queue messages to one or more threads, and will block if the queue
|
5
|
+
is empty, waking up when there is another message available.
|
6
|
+
|
7
|
+
Because this is derived directly from the Array class, it has all the
|
8
|
+
expected Array functionality, with the appropriate wrappers for thread
|
9
|
+
safety.
|
10
|
+
|
11
|
+
== Gem Version
|
12
|
+
{<img src="https://badge.fury.io/rb/queue_ding.png" alt="Gem Version" />}[http://badge.fury.io/rb/queue_ding]
|
13
|
+
|
14
|
+
== Usage
|
15
|
+
|
16
|
+
== Examples
|
17
|
+
|
18
|
+
This is taken from the rspec tests.
|
19
|
+
|
20
|
+
require 'queue_ding'
|
21
|
+
include QueueDing
|
22
|
+
|
23
|
+
queue = QDing.new
|
24
|
+
|
25
|
+
tout = Thread.new do
|
26
|
+
(0..1000).each{ |j|
|
27
|
+
(i, num) = @queue.next
|
28
|
+
expect(j).to eq i
|
29
|
+
expect(num).to eq j * 7 + 3
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
tin = Thread.new do
|
34
|
+
(0..1000).map{|i| [i, i * 7 + 3]}.each{|pair| @queue << pair }
|
35
|
+
end
|
36
|
+
|
37
|
+
tin.join
|
38
|
+
tout.join
|
39
|
+
|
40
|
+
|
41
|
+
== Future Proposals
|
42
|
+
|
43
|
+
== Copyright
|
44
|
+
|
45
|
+
Copyright (c) 2014 Fred Mitchell. See LICENSE.txt for
|
46
|
+
further details.
|
47
|
+
|
48
|
+
== Contributing to queue_ding
|
49
|
+
|
50
|
+
I am very open to any ideas you may have for new features you may want to see,
|
51
|
+
any pull requests, etc.
|
52
|
+
|
53
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
54
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
55
|
+
* Fork the project.
|
56
|
+
* Start a feature/bugfix branch.
|
57
|
+
* Commit and push until you are happy with your contribution.
|
58
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
59
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
60
|
+
|
61
|
+
== Why I Created QueueDing
|
62
|
+
|
63
|
+
I ran into an issue with Queue segfaulting on Ruby 2.1.1 and 2.1.2. I need this
|
64
|
+
for my RubyNEAT project and simply has to work. Like deep_dive, this is driven
|
65
|
+
by the RubyNEAT effort, which will be quite stringent. So expect to see further
|
66
|
+
improvements and enhancements as the needs arise.
|
67
|
+
|
68
|
+
== Funny Trivia
|
69
|
+
|
70
|
+
"Queue Ding" is actually German for "Queue Thing", so it is my hopes my German
|
71
|
+
compatriots will forgive me for any possible faux pas this might entail.
|
72
|
+
|
73
|
+
== Copyright
|
74
|
+
|
75
|
+
Copyright (c) 2014 Fred Mitchell. See LICENSE.txt for
|
76
|
+
further details.
|
77
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
require 'semver'
|
6
|
+
|
7
|
+
def s_version
|
8
|
+
SemVer.find.format "%M.%m.%p%s"
|
9
|
+
end
|
10
|
+
|
11
|
+
begin
|
12
|
+
Bundler.setup(:default, :development)
|
13
|
+
rescue Bundler::BundlerError => e
|
14
|
+
$stderr.puts e.message
|
15
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
16
|
+
exit e.status_code
|
17
|
+
end
|
18
|
+
require 'rake'
|
19
|
+
|
20
|
+
require 'jeweler'
|
21
|
+
Jeweler::Tasks.new do |gem|
|
22
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
23
|
+
gem.name = "queue_ding"
|
24
|
+
gem.homepage = "http://github.com/flajann2/queue_ding"
|
25
|
+
gem.license = "MIT"
|
26
|
+
gem.summary = %Q{QueueDing is a working alternative to Queue}
|
27
|
+
gem.description = %Q{
|
28
|
+
This roughly mirrors the functionaly of Queue in allowing you to
|
29
|
+
queue messages to one or more threads, and will block if the queue
|
30
|
+
is empty, waking up when there is another message available.
|
31
|
+
}
|
32
|
+
gem.email = "lordalveric@yahoo.com"
|
33
|
+
gem.authors = ["Fred Mitchell"]
|
34
|
+
gem.required_ruby_version = '>= 2.0'
|
35
|
+
gem.version = s_version
|
36
|
+
|
37
|
+
# Exclusions
|
38
|
+
gem.files.exclude 'foo/**/*', 'rdoc/*',
|
39
|
+
'.idea/**/*', '.idea/**/.*', '.yardoc/**/*',
|
40
|
+
'Guardfile'
|
41
|
+
|
42
|
+
end
|
43
|
+
Jeweler::RubygemsDotOrgTasks.new
|
44
|
+
|
45
|
+
require 'rspec/core'
|
46
|
+
require 'rspec/core/rake_task'
|
47
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
48
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "Code coverage detail"
|
52
|
+
task :simplecov do
|
53
|
+
ENV['COVERAGE'] = "true"
|
54
|
+
Rake::Task['spec'].execute
|
55
|
+
end
|
56
|
+
|
57
|
+
task :default => :spec
|
58
|
+
|
59
|
+
require 'yard'
|
60
|
+
YARD::Rake::YardocTask.new
|
@@ -0,0 +1,68 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
= QueueDing -- a queue to handle passing of messages between threads in a thread safe manner
|
3
|
+
|
4
|
+
This is based on and extends the Array class, and wraps it with semaphores so that
|
5
|
+
messages -- any arbitrary objects -- can be added to and removed from the Array queue across
|
6
|
+
multiple threads.
|
7
|
+
|
8
|
+
Note that any object added to this QueueDing should probably be frozen, but if it is clear
|
9
|
+
that whomever removes the object from the QDing now owns that object, that requirement can
|
10
|
+
be relaxed.
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'aquarium'
|
14
|
+
require 'thread'
|
15
|
+
|
16
|
+
module QueueDing
|
17
|
+
|
18
|
+
# QDing is basically an extension of the Array class for queuing purposes.
|
19
|
+
# We add QDing#next as a blocking get the next element, as well as
|
20
|
+
# QDing#dequeue which is an alias for Array#pop. Conversely, we add
|
21
|
+
# QDing#enqueue, which is just an alias for Array#unshift.
|
22
|
+
class QDing < Array
|
23
|
+
include Aquarium::DSL
|
24
|
+
|
25
|
+
attr_accessor :semaphore, :resource
|
26
|
+
|
27
|
+
def initialize
|
28
|
+
super
|
29
|
+
@semaphore = Mutex.new
|
30
|
+
@resource = ConditionVariable.new
|
31
|
+
end
|
32
|
+
|
33
|
+
alias_method :next, :shift
|
34
|
+
alias_method :dequeue, :shift
|
35
|
+
alias_method :enqueue, :push
|
36
|
+
alias_method :enqueue, :push
|
37
|
+
# enqueue, and others that need protection for multithreading
|
38
|
+
around calls_to: [:<<,
|
39
|
+
:enqueue,
|
40
|
+
:unshift
|
41
|
+
] do |join_point, q, *args|
|
42
|
+
result = nil
|
43
|
+
q.semaphore.synchronize {
|
44
|
+
result = join_point.proceed
|
45
|
+
q.resource.signal
|
46
|
+
}
|
47
|
+
result
|
48
|
+
end
|
49
|
+
|
50
|
+
# dequeue
|
51
|
+
around calls_to: [:pop,
|
52
|
+
:next,
|
53
|
+
:dequeue
|
54
|
+
] do |join_point, q, *args|
|
55
|
+
result = nil
|
56
|
+
q.semaphore.synchronize {
|
57
|
+
while q.empty?
|
58
|
+
q.resource.wait(q.semaphore)
|
59
|
+
end
|
60
|
+
result = join_point.proceed
|
61
|
+
}
|
62
|
+
result
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
|
data/lib/queue_ding.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'queue_ding/queue_ding'
|
data/queue_ding.gemspec
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: queue_ding 0.0.2 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "queue_ding"
|
9
|
+
s.version = "0.0.2"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.authors = ["Fred Mitchell"]
|
14
|
+
s.date = "2014-07-20"
|
15
|
+
s.description = "\n This roughly mirrors the functionaly of Queue in allowing you to\n queue messages to one or more threads, and will block if the queue\n is empty, waking up when there is another message available.\n "
|
16
|
+
s.email = "lordalveric@yahoo.com"
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".rspec",
|
24
|
+
".semver",
|
25
|
+
"Gemfile",
|
26
|
+
"Gemfile.lock",
|
27
|
+
"LICENSE.txt",
|
28
|
+
"README.rdoc",
|
29
|
+
"Rakefile",
|
30
|
+
"lib/queue_ding.rb",
|
31
|
+
"lib/queue_ding/queue_ding.rb",
|
32
|
+
"queue_ding.gemspec",
|
33
|
+
"spec/queue_ding_spec.rb",
|
34
|
+
"spec/spec_helper.rb"
|
35
|
+
]
|
36
|
+
s.homepage = "http://github.com/flajann2/queue_ding"
|
37
|
+
s.licenses = ["MIT"]
|
38
|
+
s.required_ruby_version = Gem::Requirement.new(">= 2.0")
|
39
|
+
s.rubygems_version = "2.2.2"
|
40
|
+
s.summary = "QueueDing is a working alternative to Queue"
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
s.specification_version = 4
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_runtime_dependency(%q<aquarium>, ["~> 0"])
|
47
|
+
s.add_development_dependency(%q<rspec>, ["~> 2"])
|
48
|
+
s.add_development_dependency(%q<yard>, ["~> 0"])
|
49
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3"])
|
50
|
+
s.add_development_dependency(%q<bundler>, ["~> 1"])
|
51
|
+
s.add_development_dependency(%q<jeweler>, ["~> 2"])
|
52
|
+
s.add_development_dependency(%q<simplecov>, ["~> 0"])
|
53
|
+
s.add_development_dependency(%q<semver>, ["~> 1"])
|
54
|
+
s.add_development_dependency(%q<guard-rspec>, ["~> 0"])
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<aquarium>, ["~> 0"])
|
57
|
+
s.add_dependency(%q<rspec>, ["~> 2"])
|
58
|
+
s.add_dependency(%q<yard>, ["~> 0"])
|
59
|
+
s.add_dependency(%q<rdoc>, ["~> 3"])
|
60
|
+
s.add_dependency(%q<bundler>, ["~> 1"])
|
61
|
+
s.add_dependency(%q<jeweler>, ["~> 2"])
|
62
|
+
s.add_dependency(%q<simplecov>, ["~> 0"])
|
63
|
+
s.add_dependency(%q<semver>, ["~> 1"])
|
64
|
+
s.add_dependency(%q<guard-rspec>, ["~> 0"])
|
65
|
+
end
|
66
|
+
else
|
67
|
+
s.add_dependency(%q<aquarium>, ["~> 0"])
|
68
|
+
s.add_dependency(%q<rspec>, ["~> 2"])
|
69
|
+
s.add_dependency(%q<yard>, ["~> 0"])
|
70
|
+
s.add_dependency(%q<rdoc>, ["~> 3"])
|
71
|
+
s.add_dependency(%q<bundler>, ["~> 1"])
|
72
|
+
s.add_dependency(%q<jeweler>, ["~> 2"])
|
73
|
+
s.add_dependency(%q<simplecov>, ["~> 0"])
|
74
|
+
s.add_dependency(%q<semver>, ["~> 1"])
|
75
|
+
s.add_dependency(%q<guard-rspec>, ["~> 0"])
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require 'thread'
|
3
|
+
|
4
|
+
CNT = 100000
|
5
|
+
CNTI = CNT
|
6
|
+
CNTO = CNT
|
7
|
+
|
8
|
+
describe QueueDing::QDing do
|
9
|
+
before(:each) do
|
10
|
+
@queue = QueueDing::QDing.new
|
11
|
+
|
12
|
+
class Foobar
|
13
|
+
def initialize
|
14
|
+
@stuff = [1, 2, 3]
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
@foo = Foobar.new
|
19
|
+
end
|
20
|
+
|
21
|
+
it "QDing can be created" do
|
22
|
+
expect(@queue).to_not be_nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it "pushes an object into the queue" do
|
26
|
+
@queue << @foo
|
27
|
+
expect(@queue.first).to eq @foo
|
28
|
+
end
|
29
|
+
|
30
|
+
it "extracts an object from the queue" do
|
31
|
+
@queue << @foo
|
32
|
+
bar = @queue.pop
|
33
|
+
expect(bar).to eq @foo
|
34
|
+
end
|
35
|
+
|
36
|
+
it "handles concurrency" do
|
37
|
+
tout = Thread.new do
|
38
|
+
(0..CNTO).each{ |j|
|
39
|
+
(i, num) = @queue.next
|
40
|
+
expect(j).to eq i
|
41
|
+
expect(num).to eq j * 7 + 3
|
42
|
+
}
|
43
|
+
end
|
44
|
+
tin = Thread.new do
|
45
|
+
(0..CNTI).map{|i| [i, i * 7 + 3]}.each{|pair| @queue << pair }
|
46
|
+
end
|
47
|
+
tin.join
|
48
|
+
tout.join
|
49
|
+
expect(@queue.empty?).to be_truthy
|
50
|
+
end
|
51
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
module SimpleCov::Configuration
|
4
|
+
def clean_filters
|
5
|
+
@filters = []
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
SimpleCov.configure do
|
10
|
+
clean_filters
|
11
|
+
load_adapter 'test_frameworks'
|
12
|
+
end
|
13
|
+
|
14
|
+
ENV["COVERAGE"] && SimpleCov.start do
|
15
|
+
add_filter "/.rvm/"
|
16
|
+
end
|
17
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
18
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
19
|
+
|
20
|
+
require 'rspec'
|
21
|
+
require 'queue_ding'
|
22
|
+
|
23
|
+
# Requires supporting files with custom matchers and macros, etc,
|
24
|
+
# in ./support/ and its subdirectories.
|
25
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
26
|
+
|
27
|
+
RSpec.configure do |config|
|
28
|
+
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: queue_ding
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fred Mitchell
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aquarium
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: yard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rdoc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: jeweler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: semver
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: guard-rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: "\n This roughly mirrors the functionaly of Queue in allowing you to\n
|
140
|
+
\ queue messages to one or more threads, and will block if the queue\n is empty,
|
141
|
+
waking up when there is another message available.\n "
|
142
|
+
email: lordalveric@yahoo.com
|
143
|
+
executables: []
|
144
|
+
extensions: []
|
145
|
+
extra_rdoc_files:
|
146
|
+
- LICENSE.txt
|
147
|
+
- README.rdoc
|
148
|
+
files:
|
149
|
+
- ".document"
|
150
|
+
- ".rspec"
|
151
|
+
- ".semver"
|
152
|
+
- Gemfile
|
153
|
+
- Gemfile.lock
|
154
|
+
- LICENSE.txt
|
155
|
+
- README.rdoc
|
156
|
+
- Rakefile
|
157
|
+
- lib/queue_ding.rb
|
158
|
+
- lib/queue_ding/queue_ding.rb
|
159
|
+
- queue_ding.gemspec
|
160
|
+
- spec/queue_ding_spec.rb
|
161
|
+
- spec/spec_helper.rb
|
162
|
+
homepage: http://github.com/flajann2/queue_ding
|
163
|
+
licenses:
|
164
|
+
- MIT
|
165
|
+
metadata: {}
|
166
|
+
post_install_message:
|
167
|
+
rdoc_options: []
|
168
|
+
require_paths:
|
169
|
+
- lib
|
170
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '2.0'
|
175
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
requirements: []
|
181
|
+
rubyforge_project:
|
182
|
+
rubygems_version: 2.2.2
|
183
|
+
signing_key:
|
184
|
+
specification_version: 4
|
185
|
+
summary: QueueDing is a working alternative to Queue
|
186
|
+
test_files: []
|