@@ -30,16 +30,16 @@ where Upstream.Element == ArraySlice<UInt8> {
30
30
31
31
/// An optional closure that determines whether the given byte sequence is the terminating byte sequence defined by the API.
32
32
/// - Parameter: A byte chunk.
33
- /// - Returns: `True` if the given byte sequence is the terminating byte sequence defined by the API .
34
- private let terminate : ( @Sendable ( ArraySlice < UInt8 > ) -> Bool ) ?
33
+ /// - Returns: `True` until the terminating byte sequence is received .
34
+ private let predicate : ( @Sendable ( ArraySlice < UInt8 > ) -> Bool ) ?
35
35
36
36
/// Creates a new sequence.
37
37
/// - Parameters:
38
38
/// - upstream: The upstream sequence of arbitrary byte chunks.
39
- /// - terminate : An optional closure that determines whether the given byte sequence is the terminating byte sequence defined by the API.
40
- public init ( upstream: Upstream , terminate : ( @Sendable ( ArraySlice < UInt8 > ) -> Bool ) ? ) {
39
+ /// - while : An optional closure that determines whether the given byte sequence is the terminating byte sequence defined by the API.
40
+ public init ( upstream: Upstream , while predicate : ( @Sendable ( ArraySlice < UInt8 > ) -> Bool ) ? ) {
41
41
self . upstream = upstream
42
- self . terminate = terminate
42
+ self . predicate = predicate
43
43
}
44
44
}
45
45
@@ -60,13 +60,13 @@ extension ServerSentEventsDeserializationSequence: AsyncSequence {
60
60
61
61
/// An optional closure that determines whether the given byte sequence is the terminating byte sequence defined by the API.
62
62
/// - Parameter: A byte chunk.
63
- /// - Returns: `True` if the given byte sequence is the terminating byte sequence defined by the API .
64
- let terminate : ( ( ArraySlice < UInt8 > ) -> Bool ) ?
63
+ /// - Returns: `True` until the terminating byte sequence is received .
64
+ let predicate : ( ( ArraySlice < UInt8 > ) -> Bool ) ?
65
65
66
- init ( upstream: any AsyncIteratorProtocol , terminate : ( ( ArraySlice < UInt8 > ) -> Bool ) ? ) {
66
+ init ( upstream: any AsyncIteratorProtocol , while predicate : ( ( ArraySlice < UInt8 > ) -> Bool ) ? ) {
67
67
self . upstream = upstream as! UpstreamIterator
68
- self . stateMachine = . init( terminate : terminate )
69
- self . terminate = terminate
68
+ self . stateMachine = . init( while : predicate )
69
+ self . predicate = predicate
70
70
}
71
71
72
72
/// Asynchronously advances to the next element and returns it, or ends the
@@ -91,7 +91,7 @@ extension ServerSentEventsDeserializationSequence: AsyncSequence {
91
91
/// Creates the asynchronous iterator that produces elements of this
92
92
/// asynchronous sequence.
93
93
public func makeAsyncIterator( ) -> Iterator < Upstream . AsyncIterator > {
94
- Iterator ( upstream: upstream. makeAsyncIterator ( ) , terminate : terminate )
94
+ Iterator ( upstream: upstream. makeAsyncIterator ( ) , while : predicate )
95
95
}
96
96
}
97
97
@@ -102,27 +102,27 @@ extension AsyncSequence where Element == ArraySlice<UInt8>, Self: Sendable {
102
102
/// Use this method if the event's `data` field is not JSON, or if you don't want to parse it using `asDecodedServerSentEventsWithJSONData`.
103
103
/// - Parameter: An optional closure that determines whether the given byte sequence is the terminating byte sequence defined by the API.
104
104
/// - Returns: A sequence that provides the events.
105
- public func asDecodedServerSentEvents( terminate : ( @Sendable ( ArraySlice < UInt8 > ) -> Bool ) ? = nil ) -> ServerSentEventsDeserializationSequence <
105
+ public func asDecodedServerSentEvents( while predicate : ( @Sendable ( ArraySlice < UInt8 > ) -> Bool ) ? = nil ) -> ServerSentEventsDeserializationSequence <
106
106
ServerSentEventsLineDeserializationSequence < Self >
107
- > { . init( upstream: ServerSentEventsLineDeserializationSequence ( upstream: self ) , terminate : terminate ) }
107
+ > { . init( upstream: ServerSentEventsLineDeserializationSequence ( upstream: self ) , while : predicate ) }
108
108
109
109
/// Returns another sequence that decodes each event's data as the provided type using the provided decoder.
110
110
///
111
111
/// Use this method if the event's `data` field is JSON.
112
112
/// - Parameters:
113
113
/// - dataType: The type to decode the JSON data into.
114
114
/// - decoder: The JSON decoder to use.
115
- /// - terminate : An optional closure that determines whether the given byte sequence is the terminating byte sequence defined by the API.
115
+ /// - while : An optional closure that determines whether the given byte sequence is the terminating byte sequence defined by the API.
116
116
/// - Returns: A sequence that provides the events with the decoded JSON data.
117
117
public func asDecodedServerSentEventsWithJSONData< JSONDataType: Decodable > (
118
118
of dataType: JSONDataType . Type = JSONDataType . self,
119
119
decoder: JSONDecoder = . init( ) ,
120
- terminate : ( @Sendable ( ArraySlice < UInt8 > ) -> Bool ) ? = nil
120
+ while predicate : ( @Sendable ( ArraySlice < UInt8 > ) -> Bool ) ? = nil
121
121
) -> AsyncThrowingMapSequence <
122
122
ServerSentEventsDeserializationSequence < ServerSentEventsLineDeserializationSequence < Self > > ,
123
123
ServerSentEventWithJSONData < JSONDataType >
124
124
> {
125
- asDecodedServerSentEvents ( terminate : terminate )
125
+ asDecodedServerSentEvents ( while : predicate )
126
126
. map { event in
127
127
ServerSentEventWithJSONData (
128
128
event: event. event,
@@ -160,13 +160,13 @@ extension ServerSentEventsDeserializationSequence.Iterator {
160
160
161
161
/// An optional closure that determines whether the given byte sequence is the terminating byte sequence defined by the API.
162
162
/// - Parameter: A sequence of byte chunks.
163
- /// - Returns: `True` if the given byte sequence is the terminating byte sequence defined by the API .
164
- let terminate : ( ( ArraySlice < UInt8 > ) -> Bool ) ?
163
+ /// - Returns: `True` until the terminating byte sequence is received .
164
+ let predicate : ( ( ArraySlice < UInt8 > ) -> Bool ) ?
165
165
166
166
/// Creates a new state machine.
167
- init ( terminate : ( ( ArraySlice < UInt8 > ) -> Bool ) ? = nil ) {
167
+ init ( while predicate : ( ( ArraySlice < UInt8 > ) -> Bool ) ? = nil ) {
168
168
self . state = . accumulatingEvent( . init( ) , buffer: [ ] )
169
- self . terminate = terminate }
169
+ self . predicate = predicate }
170
170
171
171
/// An action returned by the `next` method.
172
172
enum NextAction {
@@ -198,9 +198,9 @@ extension ServerSentEventsDeserializationSequence.Iterator {
198
198
// If the last character of data is a newline, strip it.
199
199
if event. data? . hasSuffix ( " \n " ) ?? false { event. data? . removeLast ( ) }
200
200
201
- if let terminate = terminate {
201
+ if let predicate = predicate {
202
202
if let data = event. data {
203
- if terminate ( ArraySlice ( Data ( data. utf8) ) ) {
203
+ if predicate ( ArraySlice ( Data ( data. utf8) ) ) {
204
204
return . returnNil
205
205
}
206
206
}
0 commit comments