concurrent-ruby 0.2.1 → 0.2.2

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.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -21
  3. data/README.md +276 -275
  4. data/lib/concurrent.rb +28 -28
  5. data/lib/concurrent/agent.rb +114 -114
  6. data/lib/concurrent/cached_thread_pool.rb +131 -131
  7. data/lib/concurrent/defer.rb +65 -65
  8. data/lib/concurrent/event.rb +60 -60
  9. data/lib/concurrent/event_machine_defer_proxy.rb +23 -23
  10. data/lib/concurrent/executor.rb +96 -96
  11. data/lib/concurrent/fixed_thread_pool.rb +99 -99
  12. data/lib/concurrent/functions.rb +120 -120
  13. data/lib/concurrent/future.rb +42 -42
  14. data/lib/concurrent/global_thread_pool.rb +24 -16
  15. data/lib/concurrent/goroutine.rb +29 -29
  16. data/lib/concurrent/null_thread_pool.rb +22 -22
  17. data/lib/concurrent/obligation.rb +67 -67
  18. data/lib/concurrent/promise.rb +174 -174
  19. data/lib/concurrent/reactor.rb +166 -166
  20. data/lib/concurrent/reactor/drb_async_demux.rb +83 -83
  21. data/lib/concurrent/reactor/tcp_sync_demux.rb +131 -131
  22. data/lib/concurrent/supervisor.rb +105 -105
  23. data/lib/concurrent/thread_pool.rb +76 -76
  24. data/lib/concurrent/utilities.rb +32 -32
  25. data/lib/concurrent/version.rb +3 -3
  26. data/lib/concurrent_ruby.rb +1 -1
  27. data/md/agent.md +123 -123
  28. data/md/defer.md +174 -174
  29. data/md/event.md +32 -32
  30. data/md/executor.md +187 -187
  31. data/md/future.md +83 -83
  32. data/md/goroutine.md +52 -52
  33. data/md/obligation.md +32 -32
  34. data/md/promise.md +227 -227
  35. data/md/thread_pool.md +224 -224
  36. data/spec/concurrent/agent_spec.rb +390 -386
  37. data/spec/concurrent/cached_thread_pool_spec.rb +125 -125
  38. data/spec/concurrent/defer_spec.rb +199 -195
  39. data/spec/concurrent/event_machine_defer_proxy_spec.rb +256 -256
  40. data/spec/concurrent/event_spec.rb +134 -134
  41. data/spec/concurrent/executor_spec.rb +200 -200
  42. data/spec/concurrent/fixed_thread_pool_spec.rb +83 -83
  43. data/spec/concurrent/functions_spec.rb +217 -217
  44. data/spec/concurrent/future_spec.rb +112 -108
  45. data/spec/concurrent/global_thread_pool_spec.rb +11 -38
  46. data/spec/concurrent/goroutine_spec.rb +67 -67
  47. data/spec/concurrent/null_thread_pool_spec.rb +57 -57
  48. data/spec/concurrent/obligation_shared.rb +132 -132
  49. data/spec/concurrent/promise_spec.rb +316 -312
  50. data/spec/concurrent/reactor/drb_async_demux_spec.rb +196 -196
  51. data/spec/concurrent/reactor/tcp_sync_demux_spec.rb +410 -410
  52. data/spec/concurrent/reactor_spec.rb +364 -364
  53. data/spec/concurrent/supervisor_spec.rb +269 -269
  54. data/spec/concurrent/thread_pool_shared.rb +204 -204
  55. data/spec/concurrent/uses_global_thread_pool_shared.rb +64 -0
  56. data/spec/concurrent/utilities_spec.rb +74 -74
  57. data/spec/spec_helper.rb +32 -32
  58. metadata +17 -19
@@ -1,74 +1,74 @@
1
- require 'spec_helper'
2
- require 'thread'
3
-
4
- describe 'utilities' do
5
-
6
- context '#atomic' do
7
-
8
- it 'calls the block' do
9
- @expected = false
10
- atomic{ @expected = true }
11
- @expected.should be_true
12
- end
13
-
14
- it 'passes all arguments to the block' do
15
- @expected = nil
16
- atomic(1, 2, 3, 4) do |a, b, c, d|
17
- @expected = [a, b, c, d]
18
- end
19
- @expected.should eq [1, 2, 3, 4]
20
- end
21
-
22
- it 'returns the result of the block' do
23
- expected = atomic{ 'foo' }
24
- expected.should eq 'foo'
25
- end
26
-
27
- it 'raises an exception if no block is given' do
28
- lambda {
29
- atomic()
30
- }.should raise_error(ArgumentError)
31
- end
32
-
33
- it 'creates a new Fiber' do
34
- fiber = Fiber.new{ 'foo' }
35
- Fiber.should_receive(:new).with(no_args()).and_return(fiber)
36
- atomic{ 'foo' }
37
- end
38
-
39
- it 'immediately runs the Fiber' do
40
- fiber = Fiber.new{ 'foo' }
41
- Fiber.stub(:new).with(no_args()).and_return(fiber)
42
- fiber.should_receive(:resume).with(no_args())
43
- atomic{ 'foo' }
44
- end
45
- end
46
-
47
- context Mutex do
48
-
49
- context '#sync_with_timeout' do
50
-
51
- it 'returns the result of the block if a lock is obtained before timeout' do
52
- mutex = Mutex.new
53
- result = mutex.sync_with_timeout(30){ 42 }
54
- result.should eq 42
55
- end
56
-
57
- it 'raises Timeout::Error if the timeout is exceeded' do
58
- mutex = Mutex.new
59
- thread = Thread.new{ mutex.synchronize{ sleep(30) } }
60
- sleep(0.1)
61
- lambda {
62
- mutex.sync_and_wait(1)
63
- }.should raise_error(NoMethodError)
64
- Thread.kill(thread)
65
- end
66
-
67
- it 'raises an exception if no block given' do
68
- lambda {
69
- Mutex.new.sync_with_timeout()
70
- }.should raise_error(ArgumentError)
71
- end
72
- end
73
- end
74
- end
1
+ require 'spec_helper'
2
+ require 'thread'
3
+
4
+ describe 'utilities' do
5
+
6
+ context '#atomic' do
7
+
8
+ it 'calls the block' do
9
+ @expected = false
10
+ atomic{ @expected = true }
11
+ @expected.should be_true
12
+ end
13
+
14
+ it 'passes all arguments to the block' do
15
+ @expected = nil
16
+ atomic(1, 2, 3, 4) do |a, b, c, d|
17
+ @expected = [a, b, c, d]
18
+ end
19
+ @expected.should eq [1, 2, 3, 4]
20
+ end
21
+
22
+ it 'returns the result of the block' do
23
+ expected = atomic{ 'foo' }
24
+ expected.should eq 'foo'
25
+ end
26
+
27
+ it 'raises an exception if no block is given' do
28
+ lambda {
29
+ atomic()
30
+ }.should raise_error(ArgumentError)
31
+ end
32
+
33
+ it 'creates a new Fiber' do
34
+ fiber = Fiber.new{ 'foo' }
35
+ Fiber.should_receive(:new).with(no_args()).and_return(fiber)
36
+ atomic{ 'foo' }
37
+ end
38
+
39
+ it 'immediately runs the Fiber' do
40
+ fiber = Fiber.new{ 'foo' }
41
+ Fiber.stub(:new).with(no_args()).and_return(fiber)
42
+ fiber.should_receive(:resume).with(no_args())
43
+ atomic{ 'foo' }
44
+ end
45
+ end
46
+
47
+ context Mutex do
48
+
49
+ context '#sync_with_timeout' do
50
+
51
+ it 'returns the result of the block if a lock is obtained before timeout' do
52
+ mutex = Mutex.new
53
+ result = mutex.sync_with_timeout(30){ 42 }
54
+ result.should eq 42
55
+ end
56
+
57
+ it 'raises Timeout::Error if the timeout is exceeded' do
58
+ mutex = Mutex.new
59
+ thread = Thread.new{ mutex.synchronize{ sleep(30) } }
60
+ sleep(0.1)
61
+ lambda {
62
+ mutex.sync_and_wait(1)
63
+ }.should raise_error(NoMethodError)
64
+ Thread.kill(thread)
65
+ end
66
+
67
+ it 'raises an exception if no block given' do
68
+ lambda {
69
+ Mutex.new.sync_with_timeout()
70
+ }.should raise_error(ArgumentError)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -1,32 +1,32 @@
1
- require 'simplecov'
2
- SimpleCov.start do
3
- project_name 'concurrent-ruby'
4
- add_filter '/md/'
5
- add_filter '/pkg/'
6
- add_filter '/spec/'
7
- add_filter '/tasks/'
8
- end
9
-
10
- require 'eventmachine'
11
-
12
- require 'concurrent'
13
- require 'concurrent/functions'
14
-
15
- require 'functional'
16
-
17
- # import all the support files
18
- Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require File.expand_path(f) }
19
-
20
- RSpec.configure do |config|
21
- config.order = 'random'
22
-
23
- config.before(:suite) do
24
- end
25
-
26
- config.before(:each) do
27
- end
28
-
29
- config.after(:each) do
30
- end
31
-
32
- end
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ project_name 'concurrent-ruby'
4
+ add_filter '/md/'
5
+ add_filter '/pkg/'
6
+ add_filter '/spec/'
7
+ add_filter '/tasks/'
8
+ end
9
+
10
+ require 'eventmachine'
11
+
12
+ require 'concurrent'
13
+ require 'concurrent/functions'
14
+
15
+ require 'functional'
16
+
17
+ # import all the support files
18
+ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require File.expand_path(f) }
19
+
20
+ RSpec.configure do |config|
21
+ config.order = 'random'
22
+
23
+ config.before(:suite) do
24
+ end
25
+
26
+ config.before(:each) do
27
+ end
28
+
29
+ config.after(:each) do
30
+ end
31
+
32
+ end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: concurrent-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
5
- prerelease:
4
+ version: 0.2.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jerry D'Antonio
@@ -14,7 +13,6 @@ dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: functional-ruby
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,22 +27,20 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: bundler
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
- description: ! " Modern concurrency tools including agents, futures, promises,
47
- thread pools, reactors, and more.\n Inspired by Erlang, Clojure, Go, JavaScript,
48
- actors, and classic concurrency patterns.\n"
41
+ description: |2
42
+ Modern concurrency tools including agents, futures, promises, thread pools, reactors, supervisors, and more.
43
+ Inspired by Erlang, Clojure, Go, JavaScript, actors, and classic concurrency patterns.
49
44
  email: jerry.dantonio@gmail.com
50
45
  executables: []
51
46
  extensions: []
@@ -106,33 +101,35 @@ files:
106
101
  - spec/concurrent/reactor_spec.rb
107
102
  - spec/concurrent/supervisor_spec.rb
108
103
  - spec/concurrent/thread_pool_shared.rb
104
+ - spec/concurrent/uses_global_thread_pool_shared.rb
109
105
  - spec/concurrent/utilities_spec.rb
110
106
  - spec/spec_helper.rb
111
107
  homepage: http://www.concurrent-ruby.com
112
108
  licenses:
113
109
  - MIT
114
- post_install_message: ! " future = Concurrent::Future.new{ 'Hello, world!' }\n
115
- \ puts future.value\n #=> Hello, world!\n"
110
+ metadata: {}
111
+ post_install_message: |2
112
+ future = Concurrent::Future.new{ 'Hello, world!' }
113
+ puts future.value
114
+ #=> Hello, world!
116
115
  rdoc_options: []
117
116
  require_paths:
118
117
  - lib
119
118
  required_ruby_version: !ruby/object:Gem::Requirement
120
- none: false
121
119
  requirements:
122
- - - ! '>='
120
+ - - '>='
123
121
  - !ruby/object:Gem::Version
124
122
  version: 1.9.2
125
123
  required_rubygems_version: !ruby/object:Gem::Requirement
126
- none: false
127
124
  requirements:
128
- - - ! '>='
125
+ - - '>='
129
126
  - !ruby/object:Gem::Version
130
127
  version: '0'
131
128
  requirements: []
132
129
  rubyforge_project:
133
- rubygems_version: 1.8.24
130
+ rubygems_version: 2.0.6
134
131
  signing_key:
135
- specification_version: 3
132
+ specification_version: 4
136
133
  summary: Modern concurrency tools including agents, futures, promises, thread pools,
137
134
  reactors, and more.
138
135
  test_files:
@@ -155,5 +152,6 @@ test_files:
155
152
  - spec/concurrent/reactor_spec.rb
156
153
  - spec/concurrent/supervisor_spec.rb
157
154
  - spec/concurrent/thread_pool_shared.rb
155
+ - spec/concurrent/uses_global_thread_pool_shared.rb
158
156
  - spec/concurrent/utilities_spec.rb
159
157
  - spec/spec_helper.rb