lazily 0.2.0 → 0.2.1
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.
- checksums.yaml +15 -0
- data/README.md +14 -0
- data/lib/lazily.rb +1 -0
- data/lib/lazily/dequeuing.rb +32 -0
- data/lib/lazily/version.rb +1 -1
- data/spec/lazily/dequeuing_spec.rb +35 -0
- metadata +8 -13
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZjcyNzBlNzc2ZDNiODVjYWY3ZmJhYTIwOWQyMmU2MDQ1ZWQyOTIyNA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MjZiZWFkNTM0YmQ2NTM4ZTA0MWE0NWYzM2Y3ZDMyNzU2YTkwMmUwOQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YTJmNmYyNzIzM2ZhN2M1OGZjZmRlNThjYzYxMmE2NDRiNzA1MzViMDg1OTNh
|
10
|
+
ZjNkZDc2NWQ2Y2YwNzQ0NjRjNzM2ODM3MGQzNGQxYjVkYWEwMWNjMWU2ZDIz
|
11
|
+
NDk0N2M3NWNlNTdhZTNmMGM1MzBmNmJkNTU3NzZkMTllMGZlNTU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZDAxM2Y1MjEyNThkMDk2NWZlM2VlNjdiN2QyOTNhMGZkYWE3NTU1MjE1ODI3
|
14
|
+
YjU0NmY5MDRmNTA2NmRjMDE2YjM1MzUwMjk1ZDc5ODRlOTY2NWVjMWQ0OWM0
|
15
|
+
Mzg5YzAxZDY4YWNhNmNlYmU3ZGEwODI1MGQyNmNmY2M3YjJjMjA=
|
data/README.md
CHANGED
@@ -86,6 +86,20 @@ Outputs will be yielded in the expected order, making it a drop-in replacement f
|
|
86
86
|
|
87
87
|
Unlike some other "parallel map" implementations, the output of `#in_threads` is lazy (though it does need to pre-fetch elements from the source collection as required to start Threads).
|
88
88
|
|
89
|
+
Lazy queue processing
|
90
|
+
---------------------
|
91
|
+
|
92
|
+
`Lazily.dequeue` makes a Queue look like a (lazy) Enumerable, making it easier to process data produced by other Threads, e.g.
|
93
|
+
|
94
|
+
q = Queue.new
|
95
|
+
Thread.new do
|
96
|
+
q << 1
|
97
|
+
q << 2
|
98
|
+
q << 3
|
99
|
+
end
|
100
|
+
|
101
|
+
Lazily.dequeue(q).take(2).to_a # => [1,2]
|
102
|
+
|
89
103
|
Lazy combination of Enumerables
|
90
104
|
-------------------------------
|
91
105
|
|
data/lib/lazily.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
require "lazily/enumerable"
|
2
|
+
|
3
|
+
module Lazily
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def dequeue(queue)
|
8
|
+
Dequeuer.new(queue)
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
class Dequeuer
|
14
|
+
|
15
|
+
include Lazily::Enumerable
|
16
|
+
|
17
|
+
def initialize(queue, terminator = nil)
|
18
|
+
@queue = queue
|
19
|
+
@terminator = terminator
|
20
|
+
end
|
21
|
+
|
22
|
+
def each
|
23
|
+
loop do
|
24
|
+
next_value = @queue.pop
|
25
|
+
break if @terminator === next_value
|
26
|
+
yield next_value
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/lib/lazily/version.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "thread"
|
3
|
+
|
4
|
+
describe Lazily, "dequeuing" do
|
5
|
+
|
6
|
+
let(:queue) { Queue.new }
|
7
|
+
|
8
|
+
describe ".dequeue" do
|
9
|
+
|
10
|
+
it "drains a queue" do
|
11
|
+
queue << "one"
|
12
|
+
queue << "two"
|
13
|
+
queue << "three"
|
14
|
+
queue << nil
|
15
|
+
Lazily.dequeue(queue).to_a.should == %w(one two three)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "polls the queue" do
|
19
|
+
lambda do
|
20
|
+
Timeout.timeout(0.1) do
|
21
|
+
Lazily.dequeue(queue).first
|
22
|
+
end
|
23
|
+
end.should raise_error(TimeoutError)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "is lazy" do
|
27
|
+
queue << "one"
|
28
|
+
Timeout.timeout(0.1) do
|
29
|
+
Lazily.dequeue(queue).first.should eq("one")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazily
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Mike Williams
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-09-29 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: ! " Lazily implements \"lazy\" versions of many Enumerable methods,\n
|
15
14
|
\ allowing streamed processing of large (or even infinite) collections.\n\n It's
|
@@ -33,6 +32,7 @@ files:
|
|
33
32
|
- lib/lazily/associating.rb
|
34
33
|
- lib/lazily/combining.rb
|
35
34
|
- lib/lazily/concatenating.rb
|
35
|
+
- lib/lazily/dequeuing.rb
|
36
36
|
- lib/lazily/enumerable.rb
|
37
37
|
- lib/lazily/filtering.rb
|
38
38
|
- lib/lazily/merging.rb
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- spec/lazily/associating_spec.rb
|
45
45
|
- spec/lazily/bugs_spec.rb
|
46
46
|
- spec/lazily/concatenating_spec.rb
|
47
|
+
- spec/lazily/dequeuing_spec.rb
|
47
48
|
- spec/lazily/filtering_spec.rb
|
48
49
|
- spec/lazily/merging_spec.rb
|
49
50
|
- spec/lazily/prefetching_spec.rb
|
@@ -53,38 +54,32 @@ files:
|
|
53
54
|
- spec/spec_helper.rb
|
54
55
|
homepage: http://github.com/mdub/lazily
|
55
56
|
licenses: []
|
57
|
+
metadata: {}
|
56
58
|
post_install_message:
|
57
59
|
rdoc_options: []
|
58
60
|
require_paths:
|
59
61
|
- lib
|
60
62
|
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
-
none: false
|
62
63
|
requirements:
|
63
64
|
- - ! '>='
|
64
65
|
- !ruby/object:Gem::Version
|
65
66
|
version: '0'
|
66
|
-
segments:
|
67
|
-
- 0
|
68
|
-
hash: 3722161259490547720
|
69
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
-
none: false
|
71
68
|
requirements:
|
72
69
|
- - ! '>='
|
73
70
|
- !ruby/object:Gem::Version
|
74
71
|
version: '0'
|
75
|
-
segments:
|
76
|
-
- 0
|
77
|
-
hash: 3722161259490547720
|
78
72
|
requirements: []
|
79
73
|
rubyforge_project:
|
80
|
-
rubygems_version:
|
74
|
+
rubygems_version: 2.0.7
|
81
75
|
signing_key:
|
82
|
-
specification_version:
|
76
|
+
specification_version: 4
|
83
77
|
summary: Lazy Enumerables for everybody!
|
84
78
|
test_files:
|
85
79
|
- spec/lazily/associating_spec.rb
|
86
80
|
- spec/lazily/bugs_spec.rb
|
87
81
|
- spec/lazily/concatenating_spec.rb
|
82
|
+
- spec/lazily/dequeuing_spec.rb
|
88
83
|
- spec/lazily/filtering_spec.rb
|
89
84
|
- spec/lazily/merging_spec.rb
|
90
85
|
- spec/lazily/prefetching_spec.rb
|