barney 0.5.0 → 0.6.0
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.
- data/ChangeLog +6 -0
- data/README.md +2 -3
- data/lib/barney/share.rb +19 -14
- data/lib/barney.rb +1 -1
- metadata +1 -1
data/ChangeLog
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
2011-03-04 Robert Gleeson <rob@flowof.info> v0.6.0
|
2
|
+
|
3
|
+
* Objects returned by IO.pipe and the current sequence are enclosed in a Struct referenced by StreamPair.
|
4
|
+
* @shared stores instances of StreamPair in an Array.
|
5
|
+
* No longer store objects returned by IO.pipe and the current sequence in a Hash.
|
6
|
+
|
1
7
|
2011-03-04 Robert Gleeson <rob@flowof.info> v0.5.0
|
2
8
|
|
3
9
|
* Solve Github Issue no. 3
|
data/README.md
CHANGED
@@ -88,12 +88,11 @@ Okay, now that we've got that out of the way, let's see what using Barney is lik
|
|
88
88
|
**API**
|
89
89
|
|
90
90
|
* [master (git)](http://rubydoc.info/github/robgleeson/Barney/master/)
|
91
|
+
* [0.6.0](http://rubydoc.info/gems/barney/0.6.0)
|
91
92
|
* [0.5.0](http://rubydoc.info/gems/barney/0.5.0)
|
92
93
|
* [0.4.1](http://rubydoc.info/gems/barney/0.4.1)
|
93
94
|
* [0.4.0](http://rubydoc.info/gems/barney/0.4.0)
|
94
|
-
*
|
95
|
-
* [0.2.0](http://rubydoc.info/gems/barney/0.2.0)
|
96
|
-
* [0.1.0](http://rubydoc.info/gems/barney/0.1.0)
|
95
|
+
* …
|
97
96
|
|
98
97
|
## License
|
99
98
|
|
data/lib/barney/share.rb
CHANGED
@@ -2,6 +2,9 @@ module Barney
|
|
2
2
|
|
3
3
|
class Share
|
4
4
|
|
5
|
+
# @api private
|
6
|
+
StreamPair = Struct.new :seq, :in, :out
|
7
|
+
|
5
8
|
@mutex = Mutex.new
|
6
9
|
|
7
10
|
class << self
|
@@ -42,7 +45,9 @@ module Barney
|
|
42
45
|
# @return [Array<Symbol>] Returns a list of all variables that are being shared.
|
43
46
|
def share *variables
|
44
47
|
variables.map(&:to_sym).each do |variable|
|
45
|
-
@shared.
|
48
|
+
if (@shared[variable].nil?) || (not @shared[variable].find { |struct| struct.seq == @seq })
|
49
|
+
@shared.store variable, (@shared[variable] || []) << StreamPair.new(@seq, *IO.pipe)
|
50
|
+
end
|
46
51
|
end
|
47
52
|
@shared.keys
|
48
53
|
end
|
@@ -73,10 +78,11 @@ module Barney
|
|
73
78
|
@context = blk.binding
|
74
79
|
@pid = Kernel.fork do
|
75
80
|
blk.call
|
76
|
-
@shared.each do |variable,
|
77
|
-
|
78
|
-
|
79
|
-
|
81
|
+
@shared.each do |variable, array|
|
82
|
+
stream = array[-1]
|
83
|
+
stream.in.close
|
84
|
+
stream.out.write Marshal.dump(eval("#{variable}", @context))
|
85
|
+
stream.out.close
|
80
86
|
end
|
81
87
|
end
|
82
88
|
|
@@ -88,17 +94,16 @@ module Barney
|
|
88
94
|
# It will block until the spawned child process has exited.
|
89
95
|
# @return [void]
|
90
96
|
def synchronize
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
pipes[seq][0].close
|
97
|
+
Barney::Share.mutex.synchronize do
|
98
|
+
@shared.each do |variable, array|
|
99
|
+
array.each do |stream|
|
100
|
+
stream.out.close
|
101
|
+
Barney::Share.value = Marshal.load stream.in.read
|
102
|
+
stream.in.close
|
98
103
|
object = eval "#{variable} = Barney::Share.value", @context
|
99
|
-
@history[seq] = (@history[seq] || {}).merge({ variable => object })
|
100
|
-
pipes.delete seq
|
104
|
+
@history[stream.seq] = (@history[stream.seq] || {}).merge!({ variable => object })
|
101
105
|
end
|
106
|
+
array.clear
|
102
107
|
end
|
103
108
|
end
|
104
109
|
end
|
data/lib/barney.rb
CHANGED