em-work_queue 0.0.1

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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -0,0 +1,3 @@
1
+ ## v0.0.1
2
+
3
+ * initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in em-work_queue.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Terry Finn
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,63 @@
1
+ # EM::WorkQueue
2
+
3
+ WorkQueue makes EventMachine's queue simpler to work with. Often when
4
+ using an EventMachine queue, you will want to work on the
5
+ queue. Often this is done by creating a Proc object and passing it as
6
+ an argument to the queue when you call pop. WorkQueue makes this
7
+ simpler by packing the queue and processing proc together. It also
8
+ makes controlling the queue processing simpler with methods like start/stop/status.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'em-work_queue'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install em-work_queue
23
+
24
+ ## Usage
25
+
26
+ ```ruby
27
+ require 'rubygems'
28
+ require 'em-work_queue'
29
+ include EM::WorkQueue
30
+
31
+ EM.run do
32
+ # Create WorkQueue instance
33
+ wq = WorkQueue.new do |i|
34
+ # do work...
35
+ puts i
36
+ end
37
+
38
+ # starts processing queue
39
+ wq.start
40
+
41
+ # push work onto queue
42
+ wq.push 'a'
43
+ wq.push 'b'
44
+ wq.push 'c'
45
+
46
+ # stop processing queue
47
+ wq.stop
48
+
49
+ # will not be processed until start is called again
50
+ wq.push 'd'
51
+
52
+ # true or false
53
+ wq.running?
54
+ end
55
+ ```
56
+
57
+ ## Contributing
58
+
59
+ 1. Fork it
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/em-work_queue/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Terry Finn"]
6
+ gem.email = ["terry@terryrfinn.com"]
7
+ gem.description = %q{Makes working with EventMachine's queue more convenient. It adds start/stop/status methods, and keeps the queue and queue logic packed together.}
8
+ gem.summary = %q{Makes working with EventMachine's queue more convenient.}
9
+ gem.homepage = "https://github.com/terryfinn/em-work_queue"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "em-work_queue"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Em::WorkQueue::VERSION
17
+
18
+ gem.add_development_dependency 'rspec', '~>2.9.0'
19
+ gem.add_dependency 'eventmachine'
20
+ end
@@ -0,0 +1,8 @@
1
+ require "em-work_queue/version"
2
+ require "eventmachine"
3
+ require "em-work_queue/work_queue"
4
+
5
+ module EventMachine
6
+ module WorkQueue
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Em
2
+ module WorkQueue
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,41 @@
1
+ module EventMachine
2
+ module WorkQueue
3
+ class WorkQueue
4
+ attr_accessor :queue, :block
5
+
6
+ def initialize(&block)
7
+ @queue = EM::Queue.new
8
+ @status = false
9
+ @block = block
10
+ end
11
+
12
+ def push(val)
13
+ self.queue.push val
14
+ end
15
+
16
+ def running?
17
+ @status
18
+ end
19
+
20
+ def jog(n = 1)
21
+ n.times { @queue.pop &@block }
22
+ end
23
+
24
+ def start
25
+ @status = true
26
+ @queue_worker = Proc.new do |i|
27
+ if running?
28
+ @block.call i
29
+ @queue.pop &@queue_worker if running?
30
+ end
31
+ end
32
+
33
+ @queue.pop &@queue_worker
34
+ end
35
+
36
+ def stop
37
+ @status = false
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+ include EM::WorkQueue
3
+
4
+ describe WorkQueue do
5
+ it 'should create a queue' do
6
+ WorkQueue.new.queue.class.should be_kind_of(EM::Queue.class)
7
+ end
8
+
9
+ it 'should push values onto the queue when push is called' do
10
+ EM.run do
11
+ subject = WorkQueue.new
12
+ subject.push 'foobar'
13
+ subject.queue.empty?.should == false
14
+ EM.stop
15
+ end
16
+ end
17
+
18
+ it 'should set running to false' do
19
+ WorkQueue.new.running?.should == false
20
+ end
21
+
22
+ it 'should set running to true when start is called' do
23
+ subject = WorkQueue.new
24
+ subject.start
25
+ subject.running?.should == true
26
+ end
27
+
28
+ it 'should set running to false when stop is called' do
29
+ subject = WorkQueue.new
30
+ subject.start
31
+ subject.stop
32
+ subject.running?.should == false
33
+ end
34
+ end
@@ -0,0 +1,14 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper.rb"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ require_relative "../lib/em-work_queue"
9
+
10
+ RSpec.configure do |config|
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: em-work_queue
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Terry Finn
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70125151762400 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.9.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70125151762400
25
+ - !ruby/object:Gem::Dependency
26
+ name: eventmachine
27
+ requirement: &70125151761520 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70125151761520
36
+ description: Makes working with EventMachine's queue more convenient. It adds start/stop/status
37
+ methods, and keeps the queue and queue logic packed together.
38
+ email:
39
+ - terry@terryrfinn.com
40
+ executables: []
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - .rspec
46
+ - CHANGELOG.md
47
+ - Gemfile
48
+ - LICENSE
49
+ - README.md
50
+ - Rakefile
51
+ - em-work_queue.gemspec
52
+ - lib/em-work_queue.rb
53
+ - lib/em-work_queue/version.rb
54
+ - lib/em-work_queue/work_queue.rb
55
+ - spec/em-work_queue_spec.rb
56
+ - spec/spec_helper.rb
57
+ homepage: https://github.com/terryfinn/em-work_queue
58
+ licenses: []
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 1.8.11
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Makes working with EventMachine's queue more convenient.
81
+ test_files:
82
+ - spec/em-work_queue_spec.rb
83
+ - spec/spec_helper.rb