ione 1.2.0.pre6 → 1.2.0.pre7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ione/future.rb +9 -5
- data/lib/ione/heap.rb +11 -3
- data/lib/ione/io/io_reactor.rb +18 -8
- data/lib/ione/version.rb +1 -1
- data/spec/ione/heap_spec.rb +22 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f489ef2fde881a219194d545c1c2ab5a80f3647
|
4
|
+
data.tar.gz: d6f2e0f0a5ae218c71a895c03b3635d74ef8c6cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d552c79337732c614279c4c531b42a20043f16949869a2587666b04cf59c4713ea85fbc09b2f6aa117f3706574c42168577db24db431d8528a5b13784064625
|
7
|
+
data.tar.gz: 6b807b0167c0f7aef38520fa181d2d391f046b5cf4faeaaa68fc1a3ba12f88a14ac1427bde9da9e4eac8f6168febdf5ad90eb2e8f24995ecf8301c4ae13340d9
|
data/lib/ione/future.rb
CHANGED
@@ -109,10 +109,14 @@ module Ione
|
|
109
109
|
# can be a splatted array or a regular array passed as sole argument)
|
110
110
|
# @return [Ione::Future] a future which represents the first completing future
|
111
111
|
def first(*futures)
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
112
|
+
if futures.size == 1 && (fs = futures.first).is_a?(Enumerable)
|
113
|
+
futures = fs
|
114
|
+
end
|
115
|
+
if futures.count == 0
|
116
|
+
resolved
|
117
|
+
else
|
118
|
+
FirstFuture.new(futures)
|
119
|
+
end
|
116
120
|
end
|
117
121
|
|
118
122
|
# Takes calls the block once for each element in an array, expecting each
|
@@ -131,7 +135,7 @@ module Ione
|
|
131
135
|
# @return [Ione::Future] a future that will resolve to an array of the values
|
132
136
|
# of the futures returned by the block
|
133
137
|
def traverse(values, &block)
|
134
|
-
all(
|
138
|
+
all(values.map(&block))
|
135
139
|
rescue => e
|
136
140
|
failed(e)
|
137
141
|
end
|
data/lib/ione/heap.rb
CHANGED
@@ -39,12 +39,14 @@ module Ione
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def delete(item)
|
42
|
-
if item == @items
|
42
|
+
if item == @items.first
|
43
43
|
pop
|
44
|
+
elsif item == @items.last
|
45
|
+
@items.pop
|
44
46
|
elsif (i = index(item))
|
45
47
|
item = @items[i]
|
46
48
|
@items[i] = @items.pop
|
47
|
-
bubble_down(i)
|
49
|
+
bubble_up(bubble_down(i))
|
48
50
|
item
|
49
51
|
end
|
50
52
|
end
|
@@ -71,12 +73,16 @@ module Ione
|
|
71
73
|
@items[index] = @items[parent_index]
|
72
74
|
@items[parent_index] = item
|
73
75
|
bubble_up(parent_index)
|
76
|
+
else
|
77
|
+
index
|
74
78
|
end
|
75
79
|
end
|
76
80
|
|
77
81
|
def bubble_down(index)
|
78
82
|
child_index = (index * 2) + 1
|
79
|
-
|
83
|
+
if child_index >= @items.length
|
84
|
+
index
|
85
|
+
else
|
80
86
|
if child_index + 1 < @items.length && @items[child_index] > @items[child_index + 1]
|
81
87
|
child_index += 1
|
82
88
|
end
|
@@ -85,6 +91,8 @@ module Ione
|
|
85
91
|
@items[index] = @items[child_index]
|
86
92
|
@items[child_index] = item
|
87
93
|
bubble_down(child_index)
|
94
|
+
else
|
95
|
+
index
|
88
96
|
end
|
89
97
|
end
|
90
98
|
end
|
data/lib/ione/io/io_reactor.rb
CHANGED
@@ -255,6 +255,7 @@ module Ione
|
|
255
255
|
def initialize
|
256
256
|
@out, @in = IO.pipe
|
257
257
|
@lock = Mutex.new
|
258
|
+
@state = :open
|
258
259
|
end
|
259
260
|
|
260
261
|
def connected?
|
@@ -270,21 +271,31 @@ module Ione
|
|
270
271
|
end
|
271
272
|
|
272
273
|
def closed?
|
273
|
-
@
|
274
|
+
@state == :closed
|
274
275
|
end
|
275
276
|
|
276
277
|
def unblock
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
278
|
+
unless closed?
|
279
|
+
@lock.lock
|
280
|
+
begin
|
281
|
+
@in.write(PING_BYTE)
|
282
|
+
ensure
|
283
|
+
@lock.unlock
|
284
|
+
end
|
285
|
+
end
|
281
286
|
end
|
282
287
|
|
283
288
|
def read
|
284
|
-
|
289
|
+
unless closed?
|
290
|
+
@out.read_nonblock(2**16)
|
291
|
+
end
|
285
292
|
end
|
286
293
|
|
287
294
|
def close
|
295
|
+
@lock.synchronize do
|
296
|
+
return if @state == :closed
|
297
|
+
@state = :closed
|
298
|
+
end
|
288
299
|
@in.close
|
289
300
|
@out.close
|
290
301
|
@in = nil
|
@@ -302,7 +313,6 @@ module Ione
|
|
302
313
|
private
|
303
314
|
|
304
315
|
PING_BYTE = "\0".freeze
|
305
|
-
DEFAULT_CONNECT_OPTIONS = {:timeout => 5}.freeze
|
306
316
|
end
|
307
317
|
|
308
318
|
# @private
|
@@ -326,7 +336,7 @@ module Ione
|
|
326
336
|
end
|
327
337
|
|
328
338
|
def to_s
|
329
|
-
"
|
339
|
+
"#<#{self.class.name}:#{object_id} @time=#{@time.to_f}>"
|
330
340
|
end
|
331
341
|
alias_method :inspect, :to_s
|
332
342
|
end
|
data/lib/ione/version.rb
CHANGED
data/spec/ione/heap_spec.rb
CHANGED
@@ -133,6 +133,28 @@ module Ione
|
|
133
133
|
heap.size.should == 2
|
134
134
|
end
|
135
135
|
|
136
|
+
it 'removes the last item from the heap' do
|
137
|
+
heap.push(1)
|
138
|
+
heap.push(2)
|
139
|
+
heap.push(3)
|
140
|
+
heap.delete(3).should_not be_nil
|
141
|
+
heap.delete(3).should be_nil
|
142
|
+
heap.delete(2).should_not be_nil
|
143
|
+
heap.delete(2).should be_nil
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'correctly re-heapifies the heap after a delete' do
|
147
|
+
heap.push(2)
|
148
|
+
heap.push(6)
|
149
|
+
heap.push(7)
|
150
|
+
heap.push(8)
|
151
|
+
heap.push(9)
|
152
|
+
heap.push(3)
|
153
|
+
heap.push(4)
|
154
|
+
heap.delete(8).should_not be_nil
|
155
|
+
heap.delete(4).should_not be_nil
|
156
|
+
end
|
157
|
+
|
136
158
|
it 'returns the item' do
|
137
159
|
heap.push(3)
|
138
160
|
heap.push(4)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ione
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.0.
|
4
|
+
version: 1.2.0.pre7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Theo Hultberg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Reactive programming framework for Ruby, painless evented IO, futures
|
14
14
|
and an efficient byte buffer
|