datapipes 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82f3fba797ae0fadf73b45ab5ac99cba0ba46e6c
4
- data.tar.gz: 84f76e38c7fa6db3b3abfc50b4bbed1ece5a8ac0
3
+ metadata.gz: b69f0bd0a67b11610394bb01fe5d5e3dccb5da8b
4
+ data.tar.gz: 1f171ea4c6f63989795bfb1cb22da5cbbb732cc5
5
5
  SHA512:
6
- metadata.gz: cc97e582f356284a454d697efb5bf12407b74bf25e6c388201cd1a76a66b46f87aad85ba6980ca3fc4738c4a45407b260716264ce4b8b37c1fd0de3a9243f37f
7
- data.tar.gz: c92abd412d2d980ac9f4362940524c88424108acb9bd20a4187dd74f5fda5097ac8649afaba498c8490022ab4957870780e6023c293343a4fe40130a39d1920e
6
+ metadata.gz: b283617335d62edffd27f34c69deca578481788e381766f9dc54adbc7742495bffa7f132c0b769f79c922d660b4e775744e6c8b14e87cc619deefc96e34a51e5
7
+ data.tar.gz: a1cfdeadae7ba85c47cc2c2cbbdb1ff2b594e186bd0391913a546ec0b0e8ceadf175d632856b7bce74403050088dc7b3e52707a127f58df3481d719ae38d6e12
data/README.md CHANGED
@@ -1,6 +1,49 @@
1
1
  datapipes [![Build Status](https://travis-ci.org/taiki45/datapipes.svg?branch=master)](https://travis-ci.org/taiki45/datapipes)
2
2
  =========
3
- datapipes is multi-streaming library.
3
+ datapipes is an asynchronous multi streaming library.
4
+
5
+ ## About
6
+ datapipes encourages to handle multi streamings asynchronously. datapipes has
7
+ a few objects sparated by its responsibility.
8
+
9
+ - __Source__ Produces resources and emits the resource to pipe.
10
+ - __Tube__ Effector for resources. Processes resource in the middle of pipe.
11
+ - __Sink__ Consumer for resources. Do something with processed resources.
12
+ - __Pipe__ Resources pass through the pipe. Handles resources asynchronously.
13
+
14
+ ```
15
+ Source
16
+ | ↓ data flow
17
+ |
18
+ Tube
19
+ | pipe is '|'
20
+ |
21
+ Consumer
22
+ ```
23
+
24
+ To handle multi streamings, datapipes offers composabiliy. Source, Tube and Sink
25
+ are composable individually. So the diagram above will be:
26
+
27
+ ```
28
+ Composed Source works asynchronously
29
+
30
+ [Source Source Source]
31
+ |
32
+ | pipe handles asynchronous
33
+ |
34
+ Tube
35
+ Tube Composed Tube has individual tube in series
36
+ Tube
37
+ Tube
38
+ |
39
+ |
40
+ |
41
+ Sink
42
+ Sink
43
+ Sink
44
+
45
+ Composed Sink works synchronously
46
+ ```
4
47
 
5
48
  ## Installation
6
49
 
@@ -17,8 +60,85 @@ Or install it yourself as:
17
60
  $ gem install datapipes
18
61
 
19
62
  ## Usage
63
+ You have to define your own Source, Tube and Sink.
64
+
65
+ A basic source is list type. it produces a value in several times.
66
+ Use `produce` method to emit data to pipe.
67
+
68
+ ```ruby
69
+ class List < Datapipes::Source
70
+ def run
71
+ (1..10).each {|i| produce(i) }
72
+ end
73
+ end
74
+ ```
75
+
76
+ Next is tube. Tube processes piped data. A example tube recieve
77
+ Integer value then increase amount of the value.
78
+
79
+ Define `accept?` to recieve the data or skip this.
80
+
81
+ ```ruby
82
+ class Triple < Datapipes::Tube
83
+ def run(data)
84
+ [data, data, data]
85
+ end
86
+
87
+ def accept?(data)
88
+ data.is_a? Integer and data > 3
89
+ end
90
+ end
91
+ ```
92
+
93
+ Sink consumes piped data. A typical sink is printing data.
94
+
95
+ ```ruby
96
+ class Print < Datapipes::Sink
97
+ def run(data)
98
+ puts data
99
+ end
100
+
101
+ def accept?(data)
102
+ data.is_a? Array and data[0] < 7
103
+ end
104
+ end
105
+ ```
106
+
107
+ You can make your own datapipe with your objects.
108
+
109
+ ```ruby
110
+ datapipe = Datapipes.new(
111
+ List.new, # A source
112
+ Triple.new, # A tube
113
+ Print.new, # A sink
114
+ Datapipes::Pipe.new # A pipe
115
+ )
116
+ ```
117
+
118
+ Then just run everything with `run_resource`.
119
+
120
+ ```ruby
121
+ datapipe.run_resource
122
+ ```
123
+
124
+ The output will be:
125
+
126
+ ```
127
+ 4
128
+ 4
129
+ 4
130
+ 5
131
+ 5
132
+ 5
133
+ 6
134
+ 6
135
+ 6
136
+ ```
137
+
138
+ Congratulation!!
20
139
 
21
- TODO: Write usage instructions here
140
+ ### Composing objects
141
+ TODO...
22
142
 
23
143
  ## Contributing
24
144
 
data/datapipes.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Datapipes::VERSION
9
9
  spec.authors = ['Taiki ONO']
10
10
  spec.email = ['taiks.4559@gmail.com']
11
- spec.summary = %q{A library for processing steamings.}
12
- spec.description = %q{A library for processing steamings.}
11
+ spec.summary = %q{An asynchronous multi steamings library.}
12
+ spec.description = %q{To handle multi steamings easily.}
13
13
  spec.homepage = 'https://github.com/taiki45/datapipes'
14
14
  spec.license = 'MIT'
15
15
 
@@ -0,0 +1,36 @@
1
+ require 'datapipes'
2
+
3
+ class List < Datapipes::Source
4
+ def run
5
+ (1..10).each {|i| produce(i) }
6
+ end
7
+ end
8
+
9
+ class Triple < Datapipes::Tube
10
+ def run(data)
11
+ [data, data, data]
12
+ end
13
+
14
+ def accept?(data)
15
+ data.is_a? Integer and data > 3
16
+ end
17
+ end
18
+
19
+ class Print < Datapipes::Sink
20
+ def run(data)
21
+ puts data
22
+ end
23
+
24
+ def accept?(data)
25
+ data.is_a? Array and data[0] < 7
26
+ end
27
+ end
28
+
29
+ datapipe = Datapipes.new(
30
+ List.new, # A source
31
+ Triple.new, # A tube
32
+ Print.new, # A sink
33
+ Datapipes::Pipe.new # A pipe
34
+ )
35
+
36
+ datapipe.run_resource
@@ -1,3 +1,3 @@
1
1
  class Datapipes
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
data/lib/datapipes.rb CHANGED
@@ -24,7 +24,7 @@ class Datapipes
24
24
  runners.each(&:join)
25
25
 
26
26
  notify_resource_ending
27
- consumer.join if consumer.status == "run"
27
+ graceful_down(consumer)
28
28
  end
29
29
 
30
30
  private
@@ -37,14 +37,22 @@ class Datapipes
37
37
  data = @tube.run_all(@pipe.pull)
38
38
  @sink.run_all(data)
39
39
  end
40
+ Thread.current.kill
40
41
  end
41
42
  end
42
43
 
43
44
  def notify_resource_ending
44
45
  @flag.enq true
46
+ Thread.pass
45
47
  end
46
48
 
47
49
  def resource_ended?
48
50
  !@flag.empty?
49
51
  end
52
+
53
+ def graceful_down(consumer)
54
+ sleep 0.1
55
+ consumer.kill if consumer.status == 'sleep'
56
+ consumer.join
57
+ end
50
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datapipes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taiki ONO
@@ -66,7 +66,7 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description: A library for processing steamings.
69
+ description: To handle multi steamings easily.
70
70
  email:
71
71
  - taiks.4559@gmail.com
72
72
  executables: []
@@ -80,6 +80,7 @@ files:
80
80
  - README.md
81
81
  - Rakefile
82
82
  - datapipes.gemspec
83
+ - examples/basics.rb
83
84
  - lib/datapipes.rb
84
85
  - lib/datapipes/basics.rb
85
86
  - lib/datapipes/basics/list.rb
@@ -117,7 +118,7 @@ rubyforge_project:
117
118
  rubygems_version: 2.2.2
118
119
  signing_key:
119
120
  specification_version: 4
120
- summary: A library for processing steamings.
121
+ summary: An asynchronous multi steamings library.
121
122
  test_files:
122
123
  - spec/basics_spec.rb
123
124
  - spec/composable_spec.rb