concurrent-ruby 0.1.0 → 0.1.1.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/LICENSE +21 -21
  2. data/README.md +279 -224
  3. data/lib/concurrent.rb +27 -20
  4. data/lib/concurrent/agent.rb +106 -130
  5. data/lib/concurrent/cached_thread_pool.rb +130 -122
  6. data/lib/concurrent/defer.rb +67 -69
  7. data/lib/concurrent/drb_async_demux.rb +72 -0
  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 +87 -0
  11. data/lib/concurrent/fixed_thread_pool.rb +89 -89
  12. data/lib/concurrent/functions.rb +120 -0
  13. data/lib/concurrent/future.rb +52 -42
  14. data/lib/concurrent/global_thread_pool.rb +3 -3
  15. data/lib/concurrent/goroutine.rb +29 -25
  16. data/lib/concurrent/obligation.rb +67 -121
  17. data/lib/concurrent/promise.rb +172 -194
  18. data/lib/concurrent/reactor.rb +162 -0
  19. data/lib/concurrent/smart_mutex.rb +66 -0
  20. data/lib/concurrent/tcp_sync_demux.rb +96 -0
  21. data/lib/concurrent/thread_pool.rb +65 -61
  22. data/lib/concurrent/utilities.rb +34 -0
  23. data/lib/concurrent/version.rb +3 -3
  24. data/lib/concurrent_ruby.rb +1 -1
  25. data/md/agent.md +123 -123
  26. data/md/defer.md +174 -174
  27. data/md/event.md +32 -32
  28. data/md/executor.md +176 -0
  29. data/md/future.md +83 -83
  30. data/md/goroutine.md +52 -52
  31. data/md/obligation.md +32 -32
  32. data/md/promise.md +225 -225
  33. data/md/thread_pool.md +197 -197
  34. data/spec/concurrent/agent_spec.rb +376 -405
  35. data/spec/concurrent/cached_thread_pool_spec.rb +112 -112
  36. data/spec/concurrent/defer_spec.rb +209 -199
  37. data/spec/concurrent/event_machine_defer_proxy_spec.rb +250 -246
  38. data/spec/concurrent/event_spec.rb +134 -134
  39. data/spec/concurrent/executor_spec.rb +146 -0
  40. data/spec/concurrent/fixed_thread_pool_spec.rb +84 -84
  41. data/spec/concurrent/functions_spec.rb +57 -0
  42. data/spec/concurrent/future_spec.rb +125 -115
  43. data/spec/concurrent/goroutine_spec.rb +67 -52
  44. data/spec/concurrent/obligation_shared.rb +121 -121
  45. data/spec/concurrent/promise_spec.rb +299 -310
  46. data/spec/concurrent/smart_mutex_spec.rb +234 -0
  47. data/spec/concurrent/thread_pool_shared.rb +209 -209
  48. data/spec/concurrent/utilities_spec.rb +74 -0
  49. data/spec/spec_helper.rb +21 -19
  50. metadata +38 -14
  51. checksums.yaml +0 -7
@@ -0,0 +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,19 +1,21 @@
1
- require 'eventmachine'
2
-
3
- require 'concurrent'
4
-
5
- # import all the support files
6
- Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require File.expand_path(f) }
7
-
8
- RSpec.configure do |config|
9
-
10
- config.before(:suite) do
11
- end
12
-
13
- config.before(:each) do
14
- end
15
-
16
- config.after(:each) do
17
- end
18
-
19
- end
1
+ require 'eventmachine'
2
+
3
+ require 'concurrent'
4
+ require 'concurrent/functions'
5
+
6
+ # import all the support files
7
+ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require File.expand_path(f) }
8
+
9
+ RSpec.configure do |config|
10
+ config.order = 'random'
11
+
12
+ config.before(:suite) do
13
+ end
14
+
15
+ config.before(:each) do
16
+ end
17
+
18
+ config.after(:each) do
19
+ end
20
+
21
+ end
metadata CHANGED
@@ -1,45 +1,52 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: concurrent-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1.pre.1
5
+ prerelease: 6
5
6
  platform: ruby
6
7
  authors:
7
8
  - Jerry D'Antonio
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-07-24 00:00:00.000000000 Z
12
+ date: 2013-08-06 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: functional-ruby
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ~>
18
20
  - !ruby/object:Gem::Version
19
- version: 0.7.0
21
+ version: 0.7.1
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ~>
25
28
  - !ruby/object:Gem::Version
26
- version: 0.7.0
29
+ version: 0.7.1
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: bundler
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
- - - '>='
35
+ - - ! '>='
32
36
  - !ruby/object:Gem::Version
33
37
  version: '0'
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
- - - '>='
43
+ - - ! '>='
39
44
  - !ruby/object:Gem::Version
40
45
  version: '0'
41
- description: |2
42
- A gem for adding Erlang, Clojure, and Go inspired concurrent programming tools to Ruby.
46
+ description: ! ' A gem for adding Erlang, Clojure, and Go inspired concurrent programming
47
+ tools to Ruby.
48
+
49
+ '
43
50
  email: jerry.dantonio@gmail.com
44
51
  executables: []
45
52
  extensions: []
@@ -52,21 +59,29 @@ files:
52
59
  - lib/concurrent/agent.rb
53
60
  - lib/concurrent/cached_thread_pool.rb
54
61
  - lib/concurrent/defer.rb
62
+ - lib/concurrent/drb_async_demux.rb
55
63
  - lib/concurrent/event.rb
56
64
  - lib/concurrent/event_machine_defer_proxy.rb
65
+ - lib/concurrent/executor.rb
57
66
  - lib/concurrent/fixed_thread_pool.rb
67
+ - lib/concurrent/functions.rb
58
68
  - lib/concurrent/future.rb
59
69
  - lib/concurrent/global_thread_pool.rb
60
70
  - lib/concurrent/goroutine.rb
61
71
  - lib/concurrent/obligation.rb
62
72
  - lib/concurrent/promise.rb
73
+ - lib/concurrent/reactor.rb
74
+ - lib/concurrent/smart_mutex.rb
75
+ - lib/concurrent/tcp_sync_demux.rb
63
76
  - lib/concurrent/thread_pool.rb
77
+ - lib/concurrent/utilities.rb
64
78
  - lib/concurrent/version.rb
65
79
  - lib/concurrent.rb
66
80
  - lib/concurrent_ruby.rb
67
81
  - md/agent.md
68
82
  - md/defer.md
69
83
  - md/event.md
84
+ - md/executor.md
70
85
  - md/future.md
71
86
  - md/goroutine.md
72
87
  - md/obligation.md
@@ -77,36 +92,41 @@ files:
77
92
  - spec/concurrent/defer_spec.rb
78
93
  - spec/concurrent/event_machine_defer_proxy_spec.rb
79
94
  - spec/concurrent/event_spec.rb
95
+ - spec/concurrent/executor_spec.rb
80
96
  - spec/concurrent/fixed_thread_pool_spec.rb
97
+ - spec/concurrent/functions_spec.rb
81
98
  - spec/concurrent/future_spec.rb
82
99
  - spec/concurrent/goroutine_spec.rb
83
100
  - spec/concurrent/obligation_shared.rb
84
101
  - spec/concurrent/promise_spec.rb
102
+ - spec/concurrent/smart_mutex_spec.rb
85
103
  - spec/concurrent/thread_pool_shared.rb
104
+ - spec/concurrent/utilities_spec.rb
86
105
  - spec/spec_helper.rb
87
106
  homepage: https://github.com/jdantonio/concurrent-ruby/
88
107
  licenses:
89
108
  - MIT
90
- metadata: {}
91
109
  post_install_message:
92
110
  rdoc_options: []
93
111
  require_paths:
94
112
  - lib
95
113
  required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
96
115
  requirements:
97
- - - '>='
116
+ - - ! '>='
98
117
  - !ruby/object:Gem::Version
99
118
  version: 1.9.2
100
119
  required_rubygems_version: !ruby/object:Gem::Requirement
120
+ none: false
101
121
  requirements:
102
- - - '>='
122
+ - - ! '>'
103
123
  - !ruby/object:Gem::Version
104
- version: '0'
124
+ version: 1.3.1
105
125
  requirements: []
106
126
  rubyforge_project:
107
- rubygems_version: 2.0.3
127
+ rubygems_version: 1.8.24
108
128
  signing_key:
109
- specification_version: 4
129
+ specification_version: 3
110
130
  summary: Erlang, Clojure, and Go inspired concurrent programming tools for Ruby.
111
131
  test_files:
112
132
  - spec/concurrent/agent_spec.rb
@@ -114,10 +134,14 @@ test_files:
114
134
  - spec/concurrent/defer_spec.rb
115
135
  - spec/concurrent/event_machine_defer_proxy_spec.rb
116
136
  - spec/concurrent/event_spec.rb
137
+ - spec/concurrent/executor_spec.rb
117
138
  - spec/concurrent/fixed_thread_pool_spec.rb
139
+ - spec/concurrent/functions_spec.rb
118
140
  - spec/concurrent/future_spec.rb
119
141
  - spec/concurrent/goroutine_spec.rb
120
142
  - spec/concurrent/obligation_shared.rb
121
143
  - spec/concurrent/promise_spec.rb
144
+ - spec/concurrent/smart_mutex_spec.rb
122
145
  - spec/concurrent/thread_pool_shared.rb
146
+ - spec/concurrent/utilities_spec.rb
123
147
  - spec/spec_helper.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 3f58685d3bea0c67b29987579c607417ba905790
4
- data.tar.gz: 82ab333727880726e30369350eaca336a81c5f2c
5
- SHA512:
6
- metadata.gz: 34d8085f8ca406fd76ecb34d78c84b8faff82f49deb52095c00093f54300beb2a024e5b3dc9bd376aaa317cb7f126bcae2a7a2b87012ef975fa9c4760b23a206
7
- data.tar.gz: f707b25361f41d930383a4e12381fbd511966a991cb68c5ae97db9fe9494278b78e165bf9f3aadbd3341c9a728c1478d74ae5a8db1482248ce0ed58d34468e33