empathy 0.0.1.RC0 → 0.0.1.RC2
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +5 -0
- data/CHANGES.md +8 -0
- data/README.md +144 -0
- data/Rakefile +4 -7
- data/TESTING.md +27 -0
- data/empathy.gemspec +5 -1
- data/lib/empathy/em/condition_variable.rb +18 -11
- data/lib/empathy/em/monitor.rb +8 -0
- data/lib/empathy/em/mutex.rb +17 -0
- data/lib/empathy/em/queue.rb +10 -30
- data/lib/empathy/em/thread.rb +91 -31
- data/lib/empathy/object.rb +3 -3
- data/lib/empathy/version.rb +1 -1
- data/lib/empathy/with_all_of_ruby.rb +8 -0
- data/lib/empathy.rb +81 -45
- data/lib/monitor.rb +209 -0
- data/mspec/lib/mspec/empathy.rb +1 -1
- data/rubyspec/monitor_spec.rb +162 -0
- data/spec/empathy_spec.rb +7 -2
- data/spec/library_spec.rb +95 -48
- data/yard/extensions.rb +24 -0
- metadata +50 -11
- data/README.rdoc +0 -135
- data/TESTING.rdoc +0 -11
- data/lib/empathy/thread.rb +0 -8
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: empathy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.RC2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,8 +10,24 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-07-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: eventmachine
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.0.0
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 1.0.0
|
15
31
|
- !ruby/object:Gem::Dependency
|
16
32
|
name: mspec
|
17
33
|
requirement: !ruby/object:Gem::Requirement
|
@@ -61,21 +77,37 @@ dependencies:
|
|
61
77
|
- !ruby/object:Gem::Version
|
62
78
|
version: '0'
|
63
79
|
- !ruby/object:Gem::Dependency
|
64
|
-
name:
|
80
|
+
name: yard
|
65
81
|
requirement: !ruby/object:Gem::Requirement
|
66
82
|
none: false
|
67
83
|
requirements:
|
68
|
-
- -
|
84
|
+
- - ! '>='
|
69
85
|
- !ruby/object:Gem::Version
|
70
|
-
version:
|
86
|
+
version: '0'
|
71
87
|
type: :development
|
72
88
|
prerelease: false
|
73
89
|
version_requirements: !ruby/object:Gem::Requirement
|
74
90
|
none: false
|
75
91
|
requirements:
|
76
|
-
- -
|
92
|
+
- - ! '>='
|
77
93
|
- !ruby/object:Gem::Version
|
78
|
-
version:
|
94
|
+
version: '0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: redcarpet
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
79
111
|
description: Empathic Eventmachine
|
80
112
|
email:
|
81
113
|
- grant@lastweekend.com.au
|
@@ -84,21 +116,25 @@ extensions: []
|
|
84
116
|
extra_rdoc_files: []
|
85
117
|
files:
|
86
118
|
- .gitignore
|
119
|
+
- .yardopts
|
120
|
+
- CHANGES.md
|
87
121
|
- Gemfile
|
88
122
|
- LICENSE.txt
|
89
|
-
- README.
|
123
|
+
- README.md
|
90
124
|
- Rakefile
|
91
|
-
- TESTING.
|
125
|
+
- TESTING.md
|
92
126
|
- empathy.gemspec
|
93
127
|
- empathy.mspec
|
94
128
|
- lib/empathy.rb
|
95
129
|
- lib/empathy/em/condition_variable.rb
|
130
|
+
- lib/empathy/em/monitor.rb
|
96
131
|
- lib/empathy/em/mutex.rb
|
97
132
|
- lib/empathy/em/queue.rb
|
98
133
|
- lib/empathy/em/thread.rb
|
99
134
|
- lib/empathy/object.rb
|
100
|
-
- lib/empathy/thread.rb
|
101
135
|
- lib/empathy/version.rb
|
136
|
+
- lib/empathy/with_all_of_ruby.rb
|
137
|
+
- lib/monitor.rb
|
102
138
|
- mspec/lib/mspec/empathy.rb
|
103
139
|
- mspec/lib/mspec/guards/empathy.rb
|
104
140
|
- rubyspec/core/kernel/fixtures/__method__.rb
|
@@ -184,6 +220,7 @@ files:
|
|
184
220
|
- rubyspec/library/queue/shared/length.rb
|
185
221
|
- rubyspec/library/queue/shift_spec.rb
|
186
222
|
- rubyspec/library/queue/size_spec.rb
|
223
|
+
- rubyspec/monitor_spec.rb
|
187
224
|
- rubyspec/shared/kernel/raise.rb
|
188
225
|
- rubyspec/shared/mutex/lock.rb
|
189
226
|
- rubyspec/shared/mutex/locked.rb
|
@@ -194,6 +231,7 @@ files:
|
|
194
231
|
- spec/empathy_spec.rb
|
195
232
|
- spec/library_spec.rb
|
196
233
|
- spec/spec_helper.rb
|
234
|
+
- yard/extensions.rb
|
197
235
|
homepage: http://rubygems.org/gems/empathy
|
198
236
|
licenses:
|
199
237
|
- MIT
|
@@ -215,8 +253,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
215
253
|
version: 1.3.1
|
216
254
|
requirements: []
|
217
255
|
rubyforge_project:
|
218
|
-
rubygems_version: 1.8.
|
256
|
+
rubygems_version: 1.8.25
|
219
257
|
signing_key:
|
220
258
|
specification_version: 3
|
221
259
|
summary: Make EventMachine behave like ruby
|
222
260
|
test_files: []
|
261
|
+
has_rdoc:
|
data/README.rdoc
DELETED
@@ -1,135 +0,0 @@
|
|
1
|
-
= empathy
|
2
|
-
|
3
|
-
Empathy
|
4
|
-
|
5
|
-
http://rubygems.org/gems/empathy
|
6
|
-
|
7
|
-
Make EventMachine behave like standard Ruby
|
8
|
-
|
9
|
-
== Empathic Threads
|
10
|
-
|
11
|
-
Empathy::EM module uses Fibers to provide Thread, Queue, Mutex, ConditionVariable and MonitorMixin classes that behave like the native ruby ones.
|
12
|
-
|
13
|
-
require 'eventmachine'
|
14
|
-
require 'empathy'
|
15
|
-
|
16
|
-
# start eventmachine and a main EM::Thread
|
17
|
-
Empathy.run do
|
18
|
-
thread = Empathy::EM::Thread.new do
|
19
|
-
my_thread = Empathy::EM::Thread.current
|
20
|
-
|
21
|
-
#local storage
|
22
|
-
Empathy::EM::Thread.current[:my_key] = "some value"
|
23
|
-
|
24
|
-
#pass control elsewhere
|
25
|
-
Empathy::EM::Thread.pass
|
26
|
-
|
27
|
-
Empathy::EM::Kernel.sleep(1)
|
28
|
-
|
29
|
-
1 + 2
|
30
|
-
end
|
31
|
-
|
32
|
-
thread.join
|
33
|
-
thread.value # => 3
|
34
|
-
end
|
35
|
-
|
36
|
-
Almost all Thread behaviour is provided except that one thread will never see another as "running". Where ruby's thread API raises ThreadError, Empathy::EM will raise FiberError.
|
37
|
-
|
38
|
-
== Empathic code outside of the EventMachine reactor
|
39
|
-
|
40
|
-
If your code may run inside or outside the reactor the Empathy module itself provides a set of submodules that delegate to either the native ruby class when called outside of the reactor, or to the Empathy:EM class when called inside the reactor.
|
41
|
-
|
42
|
-
require 'eventmachine'
|
43
|
-
require 'empathy'
|
44
|
-
Empathy::Thread.current.inspect # => "Thread<...>"
|
45
|
-
|
46
|
-
# normal Kernel.sleep
|
47
|
-
Empathy::Thread.sleep(1)
|
48
|
-
|
49
|
-
Empathy.event_machine? # => false
|
50
|
-
|
51
|
-
Empathy.run do
|
52
|
-
|
53
|
-
Empathy.event_machine? # => true
|
54
|
-
|
55
|
-
Empathy::Thread.new do
|
56
|
-
|
57
|
-
Empathy::Thread.current.inspect #=> "Empathy::EM::Thread<...>"
|
58
|
-
|
59
|
-
Empathy::Kernel.sleep(1)
|
60
|
-
|
61
|
-
begin
|
62
|
-
#...do something with threads...
|
63
|
-
rescue Empathy::ThreadError
|
64
|
-
# ...
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
Note that since Empathy::Thread and friends are modules, you cannot subclass them
|
70
|
-
|
71
|
-
== Empathise with all ruby code
|
72
|
-
|
73
|
-
Seamlessly Replace Ruby's native classes with the Empathy:EM ones (redefines constants), plus monkey patching of
|
74
|
-
Object#sleep and Object#at_exit
|
75
|
-
|
76
|
-
require 'empathy/thread'
|
77
|
-
# do not run any code that uses threads outside of the reactor after the above require
|
78
|
-
|
79
|
-
Empathy.run do
|
80
|
-
t = Thread.new { 1 + 2 }
|
81
|
-
|
82
|
-
t.inspect # => "Empathy::EM::Thread<.....>"
|
83
|
-
|
84
|
-
# this will be a Fiber+EM sleep, not Kernel.sleep
|
85
|
-
sleep(4)
|
86
|
-
|
87
|
-
t.join
|
88
|
-
end
|
89
|
-
|
90
|
-
Caveat: Take care with code that subclasses Thread. This can work as long as the classes are defined after
|
91
|
-
'empathy/thread' is required.
|
92
|
-
|
93
|
-
Q: But doesn't eventmachine need to use normal threads?
|
94
|
-
A: Indeed, 'empathy/thread' also defines constants in the EventMachine namespace that refer to the original Ruby classes
|
95
|
-
|
96
|
-
== Empathise a library module
|
97
|
-
|
98
|
-
module MyLibary
|
99
|
-
def create_thread
|
100
|
-
Thread.new { Thread.current.inspect }
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
# If library will only be used inside the reactor
|
105
|
-
Empathy::EM::empathise(MyLibrary)
|
106
|
-
|
107
|
-
# If library is used both inside and outside the reactor
|
108
|
-
Empathy.empathise((MyLibrary)
|
109
|
-
|
110
|
-
In both cases constants are defined in the MyLibrary namespace so that Thread, Queue etc, refer to either Empathy modules
|
111
|
-
or Empathy:EM classes. Note that any call to empathise will have the side-effect of monkey patching Object to provide EM
|
112
|
-
safe #sleep and #at_exit.
|
113
|
-
|
114
|
-
Caveat: MyLibrary must not subclass Thread etc...
|
115
|
-
|
116
|
-
== Empathy::EM::IO - Implement Ruby's Socket API over EventMachine
|
117
|
-
|
118
|
-
Work in progress - see experimental socket-io branch
|
119
|
-
|
120
|
-
== Contributing to empathy
|
121
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
122
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
123
|
-
* Fork the project
|
124
|
-
* Start a feature/bugfix branch
|
125
|
-
* Commit and push until you are happy with your contribution
|
126
|
-
* Make sure to add specs, preferably based on ruby-spec
|
127
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
128
|
-
|
129
|
-
== Copyright
|
130
|
-
|
131
|
-
Copyright (c) 2011 Christopher J. Bottaro. (Original fiber+EM concept in "strand" library)
|
132
|
-
Copyright (c) 2012,2013 Grant Gardner.
|
133
|
-
|
134
|
-
See LICENSE.txt for further details.
|
135
|
-
|
data/TESTING.rdoc
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
= Empathy Testing
|
2
|
-
|
3
|
-
== Empathy::EM
|
4
|
-
|
5
|
-
Classes in Empathy::EM module are tested using the fully empathic method - replacing Ruby's ::Thread constant with one that points to Empathy::EM::Thread etc, and then running against the subset of rubyspec to do with threads. The rubyspecs are not changed at all. Some tests are skipped (see *.mspec)
|
6
|
-
|
7
|
-
This also tests Empathy.run and the class replacement approach (including subclassing)
|
8
|
-
|
9
|
-
== Empathy module - reactor aware
|
10
|
-
|
11
|
-
We just test that the delegation works as expected, with explicit specs run under rspec
|
data/lib/empathy/thread.rb
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
require 'eventmachine'
|
2
|
-
require 'empathy'
|
3
|
-
require 'empathy/object'
|
4
|
-
|
5
|
-
module Empathy
|
6
|
-
map_classes(::EventMachine,::Object,"Thread","Queue","Mutex","ConditionVariable", "ThreadError" )
|
7
|
-
map_classes(::Object,Empathy::EM,"Thread","Queue","Mutex","ConditionVariable", "ThreadError" => FiberError)
|
8
|
-
end
|