dispatch_queue 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in dispatch_queue.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ DispatchQueue
2
+ =============
3
+
4
+ DispatchQueue is a simple way to serialize jobs.
5
+ It was done for crawling things, but could be used in any case that you need to do more than one work at a time.
6
+
7
+ With this line, we get more documentation that real code, so please see the code.
8
+
9
+
10
+ COMPATIBILITY
11
+ =============
12
+
13
+ It works with ruby 1.8 and ruby 1.9, and probably other rubies.
14
+
15
+ USAGE
16
+ =====
17
+
18
+ * The explicit way:
19
+
20
+ ```ruby
21
+ my_work_queue = DispatchQueue.new(lambda{ sleep 3 ; 5}, lambda{ 10 })
22
+ my_work_queue.sort #=> [5, 10]
23
+ ```
24
+
25
+ * The implicit way:
26
+
27
+ ```ruby
28
+ DQ[ lambda{ sleep 5 ; 3} , Proc.new{ sleep 6; 2 } ].sort #=> [2,3]
29
+ ```
30
+
31
+
32
+ REALCODE
33
+ =======
34
+
35
+ ```ruby
36
+ class DispatchQueue
37
+ include Enumerable
38
+
39
+ class << self
40
+ alias :[] :new
41
+ end
42
+
43
+ def initialize(*array)
44
+ @procs = array
45
+ end
46
+
47
+ def <<(new_one)
48
+ @procs << new_one
49
+ end
50
+
51
+ def each
52
+ @procs.map do |proc|
53
+ Thread.new{ proc.call }
54
+ end.map do |thread|
55
+ yield thread.value
56
+ end
57
+ end
58
+ end
59
+
60
+
61
+ DQ = DispatchQueue
62
+ ```
63
+
64
+ LICENSE
65
+ =======
66
+
67
+ "THE BEER-WARE LICENSE" (Revision 42):
68
+ <guillermo@cientifico.net> wrote this file. As long as you retain this notice you
69
+ can do whatever you want with this stuff. If we meet some day, and you think
70
+ this stuff is worth it, you can buy me a beer in return Guillermo Álvarez Fernández
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "test"
7
+ t.test_files = FileList['test/test*.rb']
8
+ t.verbose = true
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "dispatch_queue"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "dispatch_queue"
7
+ s.version = DispatchQueue::VERSION
8
+ s.authors = ["Guillermo Álvarez"]
9
+ s.email = ["guillermo@cientifico.net"]
10
+ s.homepage = ""
11
+ s.summary = %q{Simple way to work enqueue works}
12
+ s.description = %q{Little gem to enqueue jobs the easy way}
13
+
14
+ s.rubyforge_project = "dispatch_queue"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,28 @@
1
+ class DispatchQueue
2
+ VERSION = "1.0.4"
3
+ include Enumerable
4
+
5
+ class << self
6
+ alias :[] :new
7
+ end
8
+
9
+ def initialize(*array)
10
+ @procs = array
11
+ end
12
+
13
+ def <<(new_one)
14
+ @procs << new_one
15
+ end
16
+
17
+ def each
18
+ @procs.map do |proc|
19
+ Thread.new{ proc.call }
20
+ end.map do |thread|
21
+ yield thread.value
22
+ end
23
+ end
24
+ end
25
+
26
+
27
+ DQ = DispatchQueue
28
+
@@ -0,0 +1,16 @@
1
+ require 'test/unit'
2
+ require 'dispatch_queue'
3
+
4
+ class DispatchQueueTest < Test::Unit::TestCase
5
+ def test_DQ_is_equal_toDispatchQueue
6
+ assert_equal DQ, DispatchQueue
7
+ end
8
+
9
+ def test_it_yield_results
10
+ assert_equal [3,4], DQ[lambda{ sleep 0.1; 4}, lambda{ 3}].sort
11
+ end
12
+
13
+ def test_it_is_enumerable
14
+ assert DQ.included_modules.include?(Enumerable)
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dispatch_queue
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Guillermo Álvarez
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-08 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Little gem to enqueue jobs the easy way
15
+ email:
16
+ - guillermo@cientifico.net
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - README.md
24
+ - Rakefile
25
+ - dispatch_queue.gemspec
26
+ - lib/dispatch_queue.rb
27
+ - test/test_dispatch_queue.rb
28
+ homepage: ''
29
+ licenses: []
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project: dispatch_queue
48
+ rubygems_version: 1.8.7
49
+ signing_key:
50
+ specification_version: 3
51
+ summary: Simple way to work enqueue works
52
+ test_files:
53
+ - test/test_dispatch_queue.rb