fiber_stream 0.3.0 → 0.5.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +48 -0
- data/README.md +179 -61
- data/examples/README.md +6 -0
- data/examples/ractor_producer_sources.rb +43 -0
- data/lib/fiber_stream/flow.rb +141 -15
- data/lib/fiber_stream/internal/ractor_transfer_policy.rb +17 -0
- data/lib/fiber_stream/pipeline.rb +5 -1
- data/lib/fiber_stream/pull/compact.rb +39 -0
- data/lib/fiber_stream/pull/filter_map.rb +41 -0
- data/lib/fiber_stream/pull/map_concat.rb +56 -0
- data/lib/fiber_stream/pull/parallel_unordered_map_boundary.rb +311 -0
- data/lib/fiber_stream/pull/ractor_map_boundary.rb +50 -51
- data/lib/fiber_stream/pull/ractor_merge_ports_source.rb +18 -3
- data/lib/fiber_stream/pull/ractor_port_source.rb +39 -6
- data/lib/fiber_stream/pull/ractor_producer_source.rb +349 -0
- data/lib/fiber_stream/pull/reject.rb +40 -0
- data/lib/fiber_stream/pull/scan.rb +38 -0
- data/lib/fiber_stream/pull/tap.rb +38 -0
- data/lib/fiber_stream/pull/throttle.rb +43 -0
- data/lib/fiber_stream/pull.rb +84 -5
- data/lib/fiber_stream/ractor_producer.rb +167 -0
- data/lib/fiber_stream/rate_limiter.rb +163 -0
- data/lib/fiber_stream/running_pipeline.rb +4 -0
- data/lib/fiber_stream/sink.rb +25 -19
- data/lib/fiber_stream/source.rb +125 -22
- data/lib/fiber_stream/version.rb +1 -1
- data/lib/fiber_stream.rb +3 -0
- data/sig/fiber_stream.rbs +43 -1
- metadata +16 -3
data/sig/fiber_stream.rbs
CHANGED
|
@@ -2,7 +2,7 @@ module FiberStream
|
|
|
2
2
|
type ractor_transfer_policy = :copy | :move
|
|
3
3
|
type ractor_port_pair = { port: untyped, ack_port: untyped }
|
|
4
4
|
type ractor_map_error_kind = :input_transfer | :output_transfer | :worker | :worker_termination | :isolation
|
|
5
|
-
type ractor_port_source_error_kind = :invalid_message | :producer_failure | :receive | :ack_transfer | :cancel_transfer
|
|
5
|
+
type ractor_port_source_error_kind = :invalid_message | :producer_failure | :receive | :ack_transfer | :cancel_transfer | :producer_setup
|
|
6
6
|
type ractor_port_cancel_reason = :closed
|
|
7
7
|
|
|
8
8
|
class SchedulerRequiredError < RuntimeError
|
|
@@ -14,6 +14,19 @@ module FiberStream
|
|
|
14
14
|
class PipelineCancelledError < RuntimeError
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
+
class RateLimiter
|
|
18
|
+
class Request < Data
|
|
19
|
+
attr_reader rate: Integer
|
|
20
|
+
attr_reader per: Numeric
|
|
21
|
+
attr_reader burst: Integer
|
|
22
|
+
attr_reader permits: Integer
|
|
23
|
+
attr_reader now: Float
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def initialize: (rate: Integer, ?per: Numeric, ?burst: Integer?) ?{ (Request request) -> Numeric? } -> void
|
|
27
|
+
def acquire: (?permits: Integer) -> nil
|
|
28
|
+
end
|
|
29
|
+
|
|
17
30
|
class RactorPortSourceError < RuntimeError
|
|
18
31
|
attr_reader kind: ractor_port_source_error_kind
|
|
19
32
|
attr_reader cause_class_name: String
|
|
@@ -48,26 +61,46 @@ module FiberStream
|
|
|
48
61
|
end
|
|
49
62
|
end
|
|
50
63
|
|
|
64
|
+
class RactorProducer
|
|
65
|
+
def emit: [Elem] (Elem value, ?transfer: ractor_transfer_policy?) -> bool
|
|
66
|
+
def complete: () -> bool
|
|
67
|
+
def fail: (?untyped error, ?cause_class_name: String?, ?cause_message: String?) -> bool
|
|
68
|
+
def cancelled?: () -> bool
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
class RactorProducerGroup
|
|
72
|
+
def producer: (*untyped args, ?transfer: ractor_transfer_policy?) { (RactorProducer producer, *untyped args) -> void } -> self
|
|
73
|
+
end
|
|
74
|
+
|
|
51
75
|
class Source[Elem]
|
|
52
76
|
def self.each: [Elem] (Enumerable[Elem] enumerable) -> Source[Elem]
|
|
53
77
|
def self.io: (untyped io, ?chunk_size: Integer, ?close: bool) -> Source[String]
|
|
54
78
|
def self.ractor_port: [Elem] (untyped port, ack_port: untyped, ?ack_transfer: ractor_transfer_policy, ?cancel: bool) -> Source[Elem]
|
|
55
79
|
def self.ractor_merge_ports: [Elem] (Enumerable[ractor_port_pair] ports, ?ack_transfer: ractor_transfer_policy, ?cancel: bool) -> Source[Elem]
|
|
80
|
+
def self.ractor_producer: [Elem] (*untyped args, ?transfer: ractor_transfer_policy, ?ack_transfer: ractor_transfer_policy) { (RactorProducer producer, *untyped args) -> void } -> Source[Elem]
|
|
81
|
+
def self.ractor_merge_producers: [Elem] (?transfer: ractor_transfer_policy, ?ack_transfer: ractor_transfer_policy) { (RactorProducerGroup group) -> void } -> Source[Elem]
|
|
56
82
|
def via: [Out] (Flow[Elem, Out] flow) -> Source[Out]
|
|
57
83
|
def concat: [Other] (Source[Other] source) -> Source[Elem | Other]
|
|
58
84
|
def zip: [Other] (Source[Other] source) -> Source[[Elem, Other]]
|
|
59
85
|
def merge: [Other] (Source[Other] source) -> Source[Elem | Other]
|
|
60
86
|
def map: [Out] () { (Elem) -> Out } -> Source[Out]
|
|
61
87
|
def parallel_map: [Out] (concurrency: Integer) { (Elem) -> Out } -> Source[Out]
|
|
88
|
+
def parallel_unordered_map: [Out] (concurrency: Integer) { (Elem) -> Out } -> Source[Out]
|
|
62
89
|
def ractor_map: [Out] (workers: Integer, ?input_transfer: ractor_transfer_policy, ?output_transfer: ractor_transfer_policy) { (Elem) -> Out } -> Source[Out]
|
|
90
|
+
def filter_map: [Out] () { (Elem) -> (Out | false | nil) } -> Source[Out]
|
|
91
|
+
def compact: () -> Source[Elem]
|
|
92
|
+
def map_concat: [Out] () { (Elem) -> Enumerable[Out] } -> Source[Out]
|
|
63
93
|
def select: () { (Elem) -> boolish } -> Source[Elem]
|
|
94
|
+
def reject: () { (Elem) -> boolish } -> Source[Elem]
|
|
64
95
|
def take: (Integer count) -> Source[Elem]
|
|
65
96
|
def drop: (Integer count) -> Source[Elem]
|
|
66
97
|
def grouped: (Integer count) -> Source[Array[Elem]]
|
|
98
|
+
def scan: [Acc] (Acc initial) { (Acc, Elem) -> Acc } -> Source[Acc]
|
|
67
99
|
def take_while: () { (Elem) -> boolish } -> Source[Elem]
|
|
68
100
|
def drop_while: () { (Elem) -> boolish } -> Source[Elem]
|
|
69
101
|
def async: () -> Source[Elem]
|
|
70
102
|
def buffer: (Integer count) -> Source[Elem]
|
|
103
|
+
def throttle: (?rate: Integer, ?per: Numeric, ?burst: Integer?, ?limiter: untyped) -> Source[Elem]
|
|
71
104
|
def lines: (?chomp: bool, ?max_length: Integer?) -> Source[String]
|
|
72
105
|
def split: (String separator, ?keep_separator: bool, ?max_length: Integer?) -> Source[String]
|
|
73
106
|
def to: [Mat] (Sink[Elem, Mat] sink) -> Pipeline[Mat]
|
|
@@ -76,16 +109,24 @@ module FiberStream
|
|
|
76
109
|
|
|
77
110
|
class Flow[In, Out]
|
|
78
111
|
def self.map: [In, Out] () { (In) -> Out } -> Flow[In, Out]
|
|
112
|
+
def self.tap: [Elem] () { (Elem) -> void } -> Flow[Elem, Elem]
|
|
79
113
|
def self.parallel_map: [In, Out] (concurrency: Integer) { (In) -> Out } -> Flow[In, Out]
|
|
114
|
+
def self.parallel_unordered_map: [In, Out] (concurrency: Integer) { (In) -> Out } -> Flow[In, Out]
|
|
80
115
|
def self.ractor_map: [In, Out] (workers: Integer, ?input_transfer: ractor_transfer_policy, ?output_transfer: ractor_transfer_policy) { (In) -> Out } -> Flow[In, Out]
|
|
116
|
+
def self.filter_map: [In, Out] () { (In) -> (Out | false | nil) } -> Flow[In, Out]
|
|
117
|
+
def self.compact: [Elem] () -> Flow[Elem, Elem]
|
|
118
|
+
def self.map_concat: [In, Out] () { (In) -> Enumerable[Out] } -> Flow[In, Out]
|
|
81
119
|
def self.select: [Elem] () { (Elem) -> boolish } -> Flow[Elem, Elem]
|
|
120
|
+
def self.reject: [Elem] () { (Elem) -> boolish } -> Flow[Elem, Elem]
|
|
82
121
|
def self.take: [Elem] (Integer count) -> Flow[Elem, Elem]
|
|
83
122
|
def self.drop: [Elem] (Integer count) -> Flow[Elem, Elem]
|
|
84
123
|
def self.grouped: [Elem] (Integer count) -> Flow[Elem, Array[Elem]]
|
|
124
|
+
def self.scan: [Elem, Acc] (Acc initial) { (Acc, Elem) -> Acc } -> Flow[Elem, Acc]
|
|
85
125
|
def self.take_while: [Elem] () { (Elem) -> boolish } -> Flow[Elem, Elem]
|
|
86
126
|
def self.drop_while: [Elem] () { (Elem) -> boolish } -> Flow[Elem, Elem]
|
|
87
127
|
def self.async: [Elem] () -> Flow[Elem, Elem]
|
|
88
128
|
def self.buffer: [Elem] (Integer count) -> Flow[Elem, Elem]
|
|
129
|
+
def self.throttle: [Elem] (?rate: Integer, ?per: Numeric, ?burst: Integer?, ?limiter: untyped) -> Flow[Elem, Elem]
|
|
89
130
|
def self.lines: (?chomp: bool, ?max_length: Integer?) -> Flow[String, String]
|
|
90
131
|
def self.split: (String separator, ?keep_separator: bool, ?max_length: Integer?) -> Flow[String, String]
|
|
91
132
|
def via: [Next] (Flow[Out, Next] flow) -> Flow[In, Next]
|
|
@@ -95,6 +136,7 @@ module FiberStream
|
|
|
95
136
|
class Sink[In, Mat]
|
|
96
137
|
def self.to_a: [Elem] () -> Sink[Elem, Array[Elem]]
|
|
97
138
|
def self.first: [Elem] () -> Sink[Elem, Elem?]
|
|
139
|
+
def self.count: [Elem] () -> Sink[Elem, Integer]
|
|
98
140
|
def self.fold: [Elem, Acc] (Acc initial) { (Acc, Elem) -> Acc } -> Sink[Elem, Acc]
|
|
99
141
|
def self.foreach: [Elem] () { (Elem) -> void } -> Sink[Elem, Integer]
|
|
100
142
|
def self.io: (untyped io, ?close: bool, ?flush: bool) -> Sink[String, Integer]
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fiber_stream
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dai Akatsuka
|
|
@@ -119,32 +119,45 @@ files:
|
|
|
119
119
|
- examples/ractor_map_hashing.rb
|
|
120
120
|
- examples/ractor_merge_ports_and_map.rb
|
|
121
121
|
- examples/ractor_port_source.rb
|
|
122
|
+
- examples/ractor_producer_sources.rb
|
|
122
123
|
- lib/fiber_stream.rb
|
|
123
124
|
- lib/fiber_stream/errors.rb
|
|
124
125
|
- lib/fiber_stream/flow.rb
|
|
126
|
+
- lib/fiber_stream/internal/ractor_transfer_policy.rb
|
|
125
127
|
- lib/fiber_stream/pipeline.rb
|
|
126
128
|
- lib/fiber_stream/pull.rb
|
|
127
129
|
- lib/fiber_stream/pull/async_boundary.rb
|
|
128
130
|
- lib/fiber_stream/pull/buffer_boundary.rb
|
|
131
|
+
- lib/fiber_stream/pull/compact.rb
|
|
129
132
|
- lib/fiber_stream/pull/concat.rb
|
|
130
133
|
- lib/fiber_stream/pull/drop.rb
|
|
131
134
|
- lib/fiber_stream/pull/drop_while.rb
|
|
132
135
|
- lib/fiber_stream/pull/each.rb
|
|
136
|
+
- lib/fiber_stream/pull/filter_map.rb
|
|
133
137
|
- lib/fiber_stream/pull/grouped.rb
|
|
134
138
|
- lib/fiber_stream/pull/io_source.rb
|
|
135
139
|
- lib/fiber_stream/pull/lines.rb
|
|
136
140
|
- lib/fiber_stream/pull/map.rb
|
|
141
|
+
- lib/fiber_stream/pull/map_concat.rb
|
|
137
142
|
- lib/fiber_stream/pull/merge.rb
|
|
138
143
|
- lib/fiber_stream/pull/parallel_map_boundary.rb
|
|
144
|
+
- lib/fiber_stream/pull/parallel_unordered_map_boundary.rb
|
|
139
145
|
- lib/fiber_stream/pull/ractor_map_boundary.rb
|
|
140
146
|
- lib/fiber_stream/pull/ractor_merge_ports_source.rb
|
|
141
147
|
- lib/fiber_stream/pull/ractor_port_source.rb
|
|
148
|
+
- lib/fiber_stream/pull/ractor_producer_source.rb
|
|
149
|
+
- lib/fiber_stream/pull/reject.rb
|
|
150
|
+
- lib/fiber_stream/pull/scan.rb
|
|
142
151
|
- lib/fiber_stream/pull/select.rb
|
|
143
152
|
- lib/fiber_stream/pull/split.rb
|
|
144
153
|
- lib/fiber_stream/pull/take.rb
|
|
145
154
|
- lib/fiber_stream/pull/take_while.rb
|
|
155
|
+
- lib/fiber_stream/pull/tap.rb
|
|
156
|
+
- lib/fiber_stream/pull/throttle.rb
|
|
146
157
|
- lib/fiber_stream/pull/zip.rb
|
|
147
158
|
- lib/fiber_stream/ractor_port.rb
|
|
159
|
+
- lib/fiber_stream/ractor_producer.rb
|
|
160
|
+
- lib/fiber_stream/rate_limiter.rb
|
|
148
161
|
- lib/fiber_stream/running_pipeline.rb
|
|
149
162
|
- lib/fiber_stream/sink.rb
|
|
150
163
|
- lib/fiber_stream/source.rb
|
|
@@ -156,7 +169,7 @@ licenses:
|
|
|
156
169
|
metadata:
|
|
157
170
|
allowed_push_host: https://rubygems.org
|
|
158
171
|
homepage_uri: https://github.com/dakatsuka/fiber_stream
|
|
159
|
-
source_code_uri: https://github.com/dakatsuka/fiber_stream/tree/v0.
|
|
172
|
+
source_code_uri: https://github.com/dakatsuka/fiber_stream/tree/v0.5.0
|
|
160
173
|
changelog_uri: https://github.com/dakatsuka/fiber_stream/blob/main/CHANGELOG.md
|
|
161
174
|
rubygems_mfa_required: 'true'
|
|
162
175
|
rdoc_options: []
|
|
@@ -173,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
173
186
|
- !ruby/object:Gem::Version
|
|
174
187
|
version: '0'
|
|
175
188
|
requirements: []
|
|
176
|
-
rubygems_version: 4.0.
|
|
189
|
+
rubygems_version: 4.0.10
|
|
177
190
|
specification_version: 4
|
|
178
191
|
summary: Asynchronous, non-blocking stream processing with backpressure.
|
|
179
192
|
test_files: []
|