concurrent-ruby 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require_relative 'runnable_shared'
3
+ require_relative 'stoppable_shared'
3
4
 
4
5
  module Concurrent
5
6
 
@@ -19,6 +20,17 @@ module Concurrent
19
20
  it_should_behave_like :runnable
20
21
  end
21
22
 
23
+ context ':stoppable' do
24
+
25
+ subject do
26
+ task = TimerTask.new{ nil }
27
+ task.run!
28
+ task
29
+ end
30
+
31
+ it_should_behave_like :stoppable
32
+ end
33
+
22
34
  context 'created with #new' do
23
35
 
24
36
  context '#initialize' do
@@ -26,7 +38,31 @@ module Concurrent
26
38
  it 'raises an exception if no block given' do
27
39
  lambda {
28
40
  @subject = Concurrent::TimerTask.new
29
- }.should raise_error
41
+ }.should raise_error(ArgumentError)
42
+ end
43
+
44
+ it 'raises an exception if :execution_interval is not greater than zero' do
45
+ lambda {
46
+ @subject = Concurrent::TimerTask.new(execution_interval: 0){ nil }
47
+ }.should raise_error(ArgumentError)
48
+ end
49
+
50
+ it 'raises an exception if :execution_interval is not an integer' do
51
+ lambda {
52
+ @subject = Concurrent::TimerTask.new(execution_interval: 'one'){ nil }
53
+ }.should raise_error(ArgumentError)
54
+ end
55
+
56
+ it 'raises an exception if :timeout_interval is not greater than zero' do
57
+ lambda {
58
+ @subject = Concurrent::TimerTask.new(timeout_interval: 0){ nil }
59
+ }.should raise_error(ArgumentError)
60
+ end
61
+
62
+ it 'raises an exception if :timeout_interval is not an integer' do
63
+ lambda {
64
+ @subject = Concurrent::TimerTask.new(timeout_interval: 'one'){ nil }
65
+ }.should raise_error(ArgumentError)
30
66
  end
31
67
 
32
68
  it 'uses the default execution interval when no interval is given' do
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: concurrent-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jerry D'Antonio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-08 00:00:00.000000000 Z
11
+ date: 2014-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  description: |2
@@ -34,36 +34,38 @@ extra_rdoc_files:
34
34
  - README.md
35
35
  - LICENSE
36
36
  files:
37
- - README.md
38
37
  - LICENSE
38
+ - README.md
39
+ - lib/concurrent.rb
39
40
  - lib/concurrent/actor.rb
40
41
  - lib/concurrent/agent.rb
41
- - lib/concurrent/cached_thread_pool/worker.rb
42
42
  - lib/concurrent/cached_thread_pool.rb
43
+ - lib/concurrent/cached_thread_pool/worker.rb
44
+ - lib/concurrent/channel.rb
43
45
  - lib/concurrent/contract.rb
44
46
  - lib/concurrent/dereferenceable.rb
45
47
  - lib/concurrent/event.rb
46
48
  - lib/concurrent/event_machine_defer_proxy.rb
47
- - lib/concurrent/fixed_thread_pool/worker.rb
48
49
  - lib/concurrent/fixed_thread_pool.rb
50
+ - lib/concurrent/fixed_thread_pool/worker.rb
49
51
  - lib/concurrent/future.rb
50
52
  - lib/concurrent/global_thread_pool.rb
51
- - lib/concurrent/goroutine.rb
52
53
  - lib/concurrent/obligation.rb
54
+ - lib/concurrent/postable.rb
53
55
  - lib/concurrent/promise.rb
54
56
  - lib/concurrent/runnable.rb
55
57
  - lib/concurrent/scheduled_task.rb
58
+ - lib/concurrent/stoppable.rb
56
59
  - lib/concurrent/supervisor.rb
57
60
  - lib/concurrent/timer_task.rb
58
61
  - lib/concurrent/utilities.rb
59
62
  - lib/concurrent/version.rb
60
- - lib/concurrent.rb
61
63
  - lib/concurrent_ruby.rb
62
64
  - md/actor.md
63
65
  - md/agent.md
66
+ - md/channel.md
64
67
  - md/dereferenceable.md
65
68
  - md/future.md
66
- - md/goroutine.md
67
69
  - md/obligation.md
68
70
  - md/promise.md
69
71
  - md/scheduled_task.md
@@ -73,18 +75,20 @@ files:
73
75
  - spec/concurrent/actor_spec.rb
74
76
  - spec/concurrent/agent_spec.rb
75
77
  - spec/concurrent/cached_thread_pool_spec.rb
78
+ - spec/concurrent/channel_spec.rb
76
79
  - spec/concurrent/contract_spec.rb
77
80
  - spec/concurrent/event_machine_defer_proxy_spec.rb
78
81
  - spec/concurrent/event_spec.rb
79
82
  - spec/concurrent/fixed_thread_pool_spec.rb
80
83
  - spec/concurrent/future_spec.rb
81
84
  - spec/concurrent/global_thread_pool_spec.rb
82
- - spec/concurrent/goroutine_spec.rb
83
85
  - spec/concurrent/obligation_shared.rb
86
+ - spec/concurrent/postable_shared.rb
84
87
  - spec/concurrent/promise_spec.rb
85
88
  - spec/concurrent/runnable_shared.rb
86
89
  - spec/concurrent/runnable_spec.rb
87
90
  - spec/concurrent/scheduled_task_spec.rb
91
+ - spec/concurrent/stoppable_shared.rb
88
92
  - spec/concurrent/supervisor_spec.rb
89
93
  - spec/concurrent/thread_pool_shared.rb
90
94
  - spec/concurrent/timer_task_spec.rb
@@ -105,17 +109,17 @@ require_paths:
105
109
  - lib
106
110
  required_ruby_version: !ruby/object:Gem::Requirement
107
111
  requirements:
108
- - - '>='
112
+ - - ">="
109
113
  - !ruby/object:Gem::Version
110
114
  version: 1.9.2
111
115
  required_rubygems_version: !ruby/object:Gem::Requirement
112
116
  requirements:
113
- - - '>='
117
+ - - ">="
114
118
  - !ruby/object:Gem::Version
115
119
  version: '0'
116
120
  requirements: []
117
121
  rubyforge_project:
118
- rubygems_version: 2.1.10
122
+ rubygems_version: 2.2.0.rc.1
119
123
  signing_key:
120
124
  specification_version: 4
121
125
  summary: Modern concurrency tools including agents, futures, promises, thread pools,
@@ -124,18 +128,20 @@ test_files:
124
128
  - spec/concurrent/actor_spec.rb
125
129
  - spec/concurrent/agent_spec.rb
126
130
  - spec/concurrent/cached_thread_pool_spec.rb
131
+ - spec/concurrent/channel_spec.rb
127
132
  - spec/concurrent/contract_spec.rb
128
133
  - spec/concurrent/event_machine_defer_proxy_spec.rb
129
134
  - spec/concurrent/event_spec.rb
130
135
  - spec/concurrent/fixed_thread_pool_spec.rb
131
136
  - spec/concurrent/future_spec.rb
132
137
  - spec/concurrent/global_thread_pool_spec.rb
133
- - spec/concurrent/goroutine_spec.rb
134
138
  - spec/concurrent/obligation_shared.rb
139
+ - spec/concurrent/postable_shared.rb
135
140
  - spec/concurrent/promise_spec.rb
136
141
  - spec/concurrent/runnable_shared.rb
137
142
  - spec/concurrent/runnable_spec.rb
138
143
  - spec/concurrent/scheduled_task_spec.rb
144
+ - spec/concurrent/stoppable_shared.rb
139
145
  - spec/concurrent/supervisor_spec.rb
140
146
  - spec/concurrent/thread_pool_shared.rb
141
147
  - spec/concurrent/timer_task_spec.rb
@@ -143,3 +149,4 @@ test_files:
143
149
  - spec/concurrent/utilities_spec.rb
144
150
  - spec/spec_helper.rb
145
151
  - spec/support/functions.rb
152
+ has_rdoc:
@@ -1,25 +0,0 @@
1
- require 'thread'
2
-
3
- require 'concurrent/global_thread_pool'
4
-
5
- module Kernel
6
-
7
- # Post the given agruments and block to the Global Thread Pool.
8
- #
9
- # @param args [Array] zero or more arguments for the block
10
- # @param block [Proc] operation to be performed concurrently
11
- #
12
- # @return [true,false] success/failre of thread creation
13
- #
14
- # @note Althought based on Go's goroutines and Erlang's spawn/1,
15
- # Ruby has a vastly different runtime. Threads aren't nearly as
16
- # efficient in Ruby. Use this function appropriately.
17
- #
18
- # @see http://golang.org/doc/effective_go.html#goroutines
19
- # @see https://gobyexample.com/goroutines
20
- def go(*args, &block)
21
- return false unless block_given?
22
- $GLOBAL_THREAD_POOL.post(*args, &block)
23
- end
24
- module_function :go
25
- end
@@ -1,54 +0,0 @@
1
- # Go, Go, Gadget Goroutine!
2
-
3
- A goroutine is the simplest of the concurrency utilities in this library. It is inspired by
4
- [Go's](http://golang.org/) [goroutines](https://gobyexample.com/goroutines) and
5
- [Erlang's](http://www.erlang.org/) [spawn](http://erlangexamples.com/tag/spawn/) keyword. The
6
- `go` function is nothing more than a simple way to send a block to the global thread pool (see below)
7
- for processing.
8
-
9
- ## Examples
10
-
11
- ```ruby
12
- require 'concurrent'
13
-
14
- go('foo'){|echo| sleep(0.1); print "#{echo}\n"; sleep(0.1); print "Boom!\n" }
15
- go('bar'){|echo| sleep(0.1); print "#{echo}\n"; sleep(0.1); print "Pow!\n" }
16
- go('baz'){|echo| sleep(0.1); print "#{echo}\n"; sleep(0.1); print "Zap!\n" }
17
- sleep(0.5)
18
-
19
- #=> foo
20
- #=> bar
21
- #=> baz
22
- #=> Boom!
23
- #=> Pow!
24
- #=> Zap!
25
- ```
26
-
27
- ## Copyright
28
-
29
- *Concurrent Ruby* is Copyright © 2013 [Jerry D'Antonio](https://twitter.com/jerrydantonio).
30
- It is free software and may be redistributed under the terms specified in the LICENSE file.
31
-
32
- ## License
33
-
34
- Released under the MIT license.
35
-
36
- http://www.opensource.org/licenses/mit-license.php
37
-
38
- > Permission is hereby granted, free of charge, to any person obtaining a copy
39
- > of this software and associated documentation files (the "Software"), to deal
40
- > in the Software without restriction, including without limitation the rights
41
- > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
42
- > copies of the Software, and to permit persons to whom the Software is
43
- > furnished to do so, subject to the following conditions:
44
- >
45
- > The above copyright notice and this permission notice shall be included in
46
- > all copies or substantial portions of the Software.
47
- >
48
- > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
49
- > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
50
- > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
51
- > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
52
- > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
53
- > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
54
- > THE SOFTWARE.
@@ -1,52 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Concurrent
4
-
5
- describe '#go' do
6
-
7
- before(:each) do
8
- $GLOBAL_THREAD_POOL = CachedThreadPool.new
9
- end
10
-
11
- it 'passes all arguments to the block' do
12
- @expected = nil
13
- go(1, 2, 3){|a, b, c| @expected = [c, b, a] }
14
- sleep(0.1)
15
- @expected.should eq [3, 2, 1]
16
- end
17
-
18
- it 'returns true if the thread is successfully created' do
19
- $GLOBAL_THREAD_POOL.should_receive(:post).and_return(true)
20
- go{ nil }.should be_true
21
- end
22
-
23
- it 'returns false if the thread cannot be created' do
24
- $GLOBAL_THREAD_POOL.should_receive(:post).and_return(false)
25
- go{ nil }.should be_false
26
- end
27
-
28
- it 'immediately returns false if no block is given' do
29
- go().should be_false
30
- end
31
-
32
- it 'does not create a thread if no block is given' do
33
- $GLOBAL_THREAD_POOL.should_not_receive(:post)
34
- go()
35
- sleep(0.1)
36
- end
37
-
38
- it 'supresses exceptions on the thread' do
39
- lambda{
40
- go{ raise StandardError }
41
- sleep(0.1)
42
- }.should_not raise_error
43
- end
44
-
45
- it 'processes the block' do
46
- @expected = false
47
- go(1,2,3){|*args| @expected = args }
48
- sleep(0.1)
49
- @expected.should eq [1,2,3]
50
- end
51
- end
52
- end