threach 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.markdown +66 -0
  2. data/VERSION +1 -1
  3. metadata +43 -19
  4. data/README.rdoc +0 -17
data/README.markdown ADDED
@@ -0,0 +1,66 @@
1
+ # threach
2
+
3
+ `threach` adds to the Enumerable module to provide a threaded
4
+ version of whatever enumerator you throw at it (`each` by default).
5
+
6
+ ## Use
7
+
8
+ # You like #each? You'll love...err..probably like #threach
9
+ require 'rubygems'
10
+ require 'threach'
11
+
12
+ # Process with 2 threads. It assumes you want 'each'
13
+ # as your iterator.
14
+ (1..10).threach(2) {|i| puts i.to_s}
15
+
16
+ # You can also specify the iterator
17
+ File.open('mybigfile') do |f|
18
+ f.threach(2, :each_line) do |line|
19
+ processLine(line)
20
+ end
21
+ end
22
+
23
+ # threach does not care what the arity of your block is
24
+ # as long as it matches the iterator you ask for
25
+
26
+ ('A'..'Z').threach(3, :each_with_index) do |letter, index|
27
+ puts "#{index}: #{letter}"
28
+ end
29
+
30
+ # Or with a hash
31
+ h = {'a' => 1, 'b'=>2, 'c'=>3}
32
+ h.threach(2) do |letter, i|
33
+ puts "#{i}: #{letter}"
34
+ end
35
+
36
+ ## Why and when to use it?
37
+
38
+ Well, if you're using stock (MRI) ruby -- you probably shouldn't bother with `threach`. It'll just slow things down. But if you're using a ruby implementation that has real threads, like JRuby, this will give you relatively painless multi-threading.
39
+
40
+ You can always do something like:
41
+
42
+ if defined? JRUBY_VERSION
43
+ numthreads = 3
44
+ else
45
+ numthreads = 0
46
+ end
47
+
48
+ my_enumerable.threach(numthreads) {|i| ...}
49
+
50
+ Note the "relatively" in front of "painless" up there. The block you pass still has to be thread-safe, and there are many data structures you'll encounter that are *not* thread-safe. Scalars, arrays, and hashes are, though, under JRuby, and that'll get you pretty far.
51
+
52
+
53
+
54
+ ## Note on Patches/Pull Requests
55
+
56
+ * Fork the project.
57
+ * Make your feature addition or bug fix.
58
+ * Add tests for it. This is important so I don't break it in a
59
+ future version unintentionally.
60
+ * Commit, do not mess with rakefile, version, or history.
61
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
62
+ * Send me a pull request. Bonus points for topic branches.
63
+
64
+ ## Copyright
65
+
66
+ Copyright (c) 2010 Bill Dueber. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: threach
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
5
11
  platform: ruby
6
12
  authors:
7
13
  - Bill Dueber
@@ -9,39 +15,51 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-04-07 00:00:00 -04:00
18
+ date: 2010-07-13 00:00:00 -04:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: thoughtbot-shoulda
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
23
32
  version: "0"
24
- version:
33
+ type: :development
34
+ version_requirements: *id001
25
35
  - !ruby/object:Gem::Dependency
26
36
  name: yard
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
30
40
  requirements:
31
41
  - - ">="
32
42
  - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
33
46
  version: "0"
34
- version:
47
+ type: :development
48
+ version_requirements: *id002
35
49
  - !ruby/object:Gem::Dependency
36
50
  name: cucumber
37
- type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
40
54
  requirements:
41
55
  - - ">="
42
56
  - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
43
60
  version: "0"
44
- version:
61
+ type: :development
62
+ version_requirements: *id003
45
63
  description: An addition to the Enumerable module that allows easy use of threaded each and each-like iterators
46
64
  email: bill@dueber.com
47
65
  executables: []
@@ -50,12 +68,12 @@ extensions: []
50
68
 
51
69
  extra_rdoc_files:
52
70
  - LICENSE
53
- - README.rdoc
71
+ - README.markdown
54
72
  files:
55
73
  - .document
56
74
  - .gitignore
57
75
  - LICENSE
58
- - README.rdoc
76
+ - README.markdown
59
77
  - Rakefile
60
78
  - VERSION
61
79
  - features/step_definitions/threach_steps.rb
@@ -74,21 +92,27 @@ rdoc_options:
74
92
  require_paths:
75
93
  - lib
76
94
  required_ruby_version: !ruby/object:Gem::Requirement
95
+ none: false
77
96
  requirements:
78
97
  - - ">="
79
98
  - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
80
102
  version: "0"
81
- version:
82
103
  required_rubygems_version: !ruby/object:Gem::Requirement
104
+ none: false
83
105
  requirements:
84
106
  - - ">="
85
107
  - !ruby/object:Gem::Version
108
+ hash: 3
109
+ segments:
110
+ - 0
86
111
  version: "0"
87
- version:
88
112
  requirements: []
89
113
 
90
114
  rubyforge_project:
91
- rubygems_version: 1.3.5
115
+ rubygems_version: 1.3.7
92
116
  signing_key:
93
117
  specification_version: 3
94
118
  summary: Threaded each
data/README.rdoc DELETED
@@ -1,17 +0,0 @@
1
- = threach
2
-
3
- Description goes here.
4
-
5
- == Note on Patches/Pull Requests
6
-
7
- * Fork the project.
8
- * Make your feature addition or bug fix.
9
- * Add tests for it. This is important so I don't break it in a
10
- future version unintentionally.
11
- * Commit, do not mess with rakefile, version, or history.
12
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
- * Send me a pull request. Bonus points for topic branches.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2010 Bill Dueber. See LICENSE for details.