multithreads_each 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a130683a6f12bccade82470e106de03a23e4c0ae
4
- data.tar.gz: 60dd88c2140d5607f2fa0e3bdb2eb376e7b0953a
3
+ metadata.gz: c567f022534092bae5c9233d69d88ac45b9fe0b6
4
+ data.tar.gz: 755cbe057f425e5e1e61a9ece90a42ad6ea01201
5
5
  SHA512:
6
- metadata.gz: a8fea147af37b39cb460e9da0fe3c548aec752f3e11c7f4e628eb0a13169c01645232740d3711024da185b6dc09d75ee8782b3eb5a740eb95d039952c80ef4a4
7
- data.tar.gz: cee99b9682d2f27915977abc6f784e84596619787cbf9c750c19bc5896186a5c2df9b19834cb73c171f459615c6c5a64c18c244a57fdb136006f23442205ba12
6
+ metadata.gz: 501010ea648c2828d91e6218b2ace0cd56b4e7bdd2212dd585fab7456bcf0e3eff19e261d4a80735604169bac7313527f62f8a862fd299bf819f3d43d739c895
7
+ data.tar.gz: b348781323e09b1351ea21236b5f65f04c070959f234d262ca0aa3a75a198adbfdfa9421c9705135eb8e8cc00ab343effec628ca2d850838d84a267e1aae609f
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MultithreadsEach
2
2
 
3
- TODO: Write a gem description
3
+ Simple syntactic sugar for arrays that performs the same actions as the method each, but creates a new thread for every call
4
4
 
5
5
  ## Installation
6
6
 
@@ -8,17 +8,37 @@ Add this line to your application's Gemfile:
8
8
 
9
9
  gem 'multithreads_each'
10
10
 
11
- And then execute:
12
-
13
- $ bundle
14
-
15
11
  Or install it yourself as:
16
12
 
17
13
  $ gem install multithreads_each
18
14
 
19
15
  ## Usage
20
-
21
- TODO: Write usage instructions here
16
+ Using almost the same as the method each:
17
+
18
+ cities = %w(Moscow Berlin London Praga Kiev)
19
+
20
+ cities.multithreads_each do |city|
21
+ # Actions
22
+ end
23
+
24
+ For each element will be created a new thread:
25
+
26
+ def slow_function(foo)
27
+ sleep 5
28
+ puts foo
29
+ end
30
+
31
+ array = %w(1 2 3 4 5)
32
+
33
+ # Will be completed after ~25 seconds
34
+ array.each do |elem|
35
+ slow_function(elem)
36
+ end
37
+
38
+ # Will be completed after ~5 seconds
39
+ array.multithreads_each do |elem|
40
+ slow_function(elem)
41
+ end
22
42
 
23
43
  ## Contributing
24
44
 
data/Rakefile CHANGED
@@ -1 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -1,13 +1,6 @@
1
1
  require "multithreads_each/version"
2
+ require "multithreads_each/array_method"
2
3
 
3
- class Array
4
- def multithreads_each(options={})
5
- threads = []
4
+ module MultithreadsEach
6
5
 
7
- self.each do |n|
8
- threads << Thread.new { yield n }
9
- end
10
-
11
- threads.each { |thread| thread.join }
12
- end
13
6
  end
@@ -0,0 +1,12 @@
1
+ class Array
2
+ def multithreads_each(options={})
3
+ threads = []
4
+ without_joins = options[:without_joins]
5
+
6
+ self.each do |n|
7
+ threads << Thread.new { yield n }
8
+ end
9
+
10
+ threads.each { |thread| thread.join } unless without_joins
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module MultithreadsEach
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
23
24
  end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe MultithreadsEach do
4
+ it "threads count test" do
5
+ array = %w(1 2 3 4 5 6)
6
+
7
+ array.multithreads_each({ :without_joins => true }) do |elem|
8
+ elem
9
+ end
10
+
11
+ expect(Thread.list.count).to eq(6)
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ require 'multithreads_each'
2
+
3
+ RSpec.configure do |config|
4
+ # Some configurations here
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multithreads_each
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - TakteS
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-25 00:00:00.000000000 Z
11
+ date: 2014-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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'
41
55
  description: Simple syntactic sugar for arrays that performs the same actions as the
42
56
  method each, but creates a new thread for every call
43
57
  email:
@@ -52,8 +66,11 @@ files:
52
66
  - README.md
53
67
  - Rakefile
54
68
  - lib/multithreads_each.rb
69
+ - lib/multithreads_each/array_method.rb
55
70
  - lib/multithreads_each/version.rb
56
71
  - multithreads_each.gemspec
72
+ - spec/mulithreads_each_spec.rb
73
+ - spec/spec_helper.rb
57
74
  homepage: https://github.com/TakteS/multithreads_each
58
75
  licenses:
59
76
  - MIT
@@ -78,4 +95,6 @@ rubygems_version: 2.1.11
78
95
  signing_key:
79
96
  specification_version: 4
80
97
  summary: Multithreads each for arrays
81
- test_files: []
98
+ test_files:
99
+ - spec/mulithreads_each_spec.rb
100
+ - spec/spec_helper.rb