Skip to content

Commit 2385a74

Browse files
committed
Fix compile errors
1 parent d375c38 commit 2385a74

File tree

5 files changed

+148
-158
lines changed

5 files changed

+148
-158
lines changed

Sources/AWSLambdaRuntimeCore/LambdaHandler.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515
import Dispatch
1616
import NIOCore
17+
#if canImport(Darwin)
18+
import Darwin
19+
#else
20+
import Glibc
21+
#endif
1722

1823
// MARK: - LambdaHandler
1924

Sources/AWSLambdaRuntimeCore/LambdaRuntime+StateMachine.swift

Lines changed: 60 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -19,56 +19,56 @@ extension NewLambdaRuntime {
1919
var channel: Channel
2020
var handler: NewLambdaChannelHandler<NewLambdaRuntime>
2121
}
22-
22+
2323
struct StateMachine {
2424
enum Action {
2525
case none
2626
case createHandler(andConnection: Bool)
27-
27+
2828
case requestNextInvocation(NewLambdaChannelHandler<NewLambdaRuntime>, succeedStartPromise: EventLoopPromise<Void>?)
29-
29+
3030
case reportInvocationResult(LambdaRequestID, Result<ByteBuffer?, Error>, pipelineNextInvocationRequest: Bool, NewLambdaChannelHandler<NewLambdaRuntime>)
3131
case reportStartupError(Error, NewLambdaChannelHandler<NewLambdaRuntime>)
32-
32+
3333
case invokeHandler(Handler, Invocation, ByteBuffer)
34-
34+
3535
case failRuntime(Error, startPomise: EventLoopPromise<Void>?)
3636
}
37-
37+
3838
private enum State {
3939
case initialized
4040
case starting(EventLoopPromise<Void>?)
4141
case connected(Connection, EventLoopPromise<Void>?)
4242
case handlerCreated(Handler, EventLoopPromise<Void>?)
4343
case handlerCreationFailed(Error, EventLoopPromise<Void>?)
4444
case reportingStartupError(Connection, Error, EventLoopPromise<Void>?)
45-
45+
4646
case waitingForInvocation(Connection, Handler)
4747
case executingInvocation(Connection, Handler, LambdaRequestID)
4848
case reportingInvocationResult(Connection, Handler, nextInvocationRequestPipelined: Bool)
49-
49+
5050
case failed(Error)
5151
}
52-
52+
5353
private var markShutdown: Bool
5454
private var state: State
55-
55+
5656
init() {
5757
self.markShutdown = false
5858
self.state = .initialized
5959
}
60-
60+
6161
mutating func start(connection: Connection?, promise: EventLoopPromise<Void>?) -> Action {
6262
switch self.state {
6363
case .initialized:
6464
if let connection = connection {
6565
self.state = .connected(connection, promise)
6666
return .createHandler(andConnection: false)
6767
}
68-
68+
6969
self.state = .starting(promise)
7070
return .createHandler(andConnection: true)
71-
71+
7272
case .starting,
7373
.connected,
7474
.handlerCreated,
@@ -81,7 +81,7 @@ extension NewLambdaRuntime {
8181
preconditionFailure("Invalid state: \(self.state)")
8282
}
8383
}
84-
84+
8585
mutating func handlerCreated(_ handler: Handler) -> Action {
8686
switch self.state {
8787
case .initialized,
@@ -92,20 +92,20 @@ extension NewLambdaRuntime {
9292
.reportingInvocationResult,
9393
.reportingStartupError:
9494
preconditionFailure("Invalid state: \(self.state)")
95-
95+
9696
case .starting(let promise):
9797
self.state = .handlerCreated(handler, promise)
9898
return .none
99-
99+
100100
case .connected(let connection, let promise):
101101
self.state = .waitingForInvocation(connection, handler)
102102
return .requestNextInvocation(connection.handler, succeedStartPromise: promise)
103-
103+
104104
case .failed:
105105
return .none
106106
}
107107
}
108-
108+
109109
mutating func handlerCreationFailed(_ error: Error) -> Action {
110110
switch self.state {
111111
case .initialized,
@@ -116,20 +116,20 @@ extension NewLambdaRuntime {
116116
.reportingInvocationResult,
117117
.reportingStartupError:
118118
preconditionFailure("Invalid state: \(self.state)")
119-
119+
120120
case .starting(let promise):
121121
self.state = .handlerCreationFailed(error, promise)
122122
return .none
123-
123+
124124
case .connected(let connection, let promise):
125125
self.state = .reportingStartupError(connection, error, promise)
126126
return .reportStartupError(error, connection.handler)
127-
127+
128128
case .failed:
129129
return .none
130130
}
131131
}
132-
132+
133133
mutating func httpConnectionCreated(
134134
_ connection: Connection
135135
) -> Action {
@@ -141,24 +141,24 @@ extension NewLambdaRuntime {
141141
.reportingInvocationResult,
142142
.reportingStartupError:
143143
preconditionFailure("Invalid state: \(self.state)")
144-
144+
145145
case .starting(let promise):
146146
self.state = .connected(connection, promise)
147147
return .none
148-
148+
149149
case .handlerCreated(let handler, let promise):
150150
self.state = .waitingForInvocation(connection, handler)
151151
return .requestNextInvocation(connection.handler, succeedStartPromise: promise)
152-
152+
153153
case .handlerCreationFailed(let error, let promise):
154154
self.state = .reportingStartupError(connection, error, promise)
155155
return .reportStartupError(error, connection.handler)
156-
156+
157157
case .failed:
158158
return .none
159159
}
160160
}
161-
161+
162162
mutating func httpChannelConnectFailed(_ error: Error) -> Action {
163163
switch self.state {
164164
case .initialized,
@@ -168,24 +168,24 @@ extension NewLambdaRuntime {
168168
.reportingInvocationResult,
169169
.reportingStartupError:
170170
preconditionFailure("Invalid state: \(self.state)")
171-
171+
172172
case .starting(let promise):
173173
self.state = .failed(error)
174174
return .failRuntime(error, startPomise: promise)
175-
175+
176176
case .handlerCreated(_, let promise):
177177
self.state = .failed(error)
178178
return .failRuntime(error, startPomise: promise)
179-
179+
180180
case .handlerCreationFailed(let error, let promise):
181181
self.state = .failed(error)
182182
return .failRuntime(error, startPomise: promise)
183-
183+
184184
case .failed:
185185
return .none
186186
}
187187
}
188-
188+
189189
mutating func newInvocationReceived(_ invocation: Invocation, _ body: ByteBuffer) -> Action {
190190
switch self.state {
191191
case .initialized,
@@ -197,16 +197,16 @@ extension NewLambdaRuntime {
197197
.reportingInvocationResult,
198198
.reportingStartupError:
199199
preconditionFailure("Invalid state: \(self.state)")
200-
200+
201201
case .waitingForInvocation(let connection, let handler):
202-
self.state = .executingInvocation(connection, handler, .init(uuidString: invocation.requestID)!)
202+
self.state = .executingInvocation(connection, handler, LambdaRequestID(uuidString: invocation.requestID)!)
203203
return .invokeHandler(handler, invocation, body)
204-
204+
205205
case .failed:
206206
return .none
207207
}
208208
}
209-
209+
210210
mutating func acceptedReceived() -> Action {
211211
switch self.state {
212212
case .initialized,
@@ -216,27 +216,27 @@ extension NewLambdaRuntime {
216216
.handlerCreationFailed,
217217
.executingInvocation:
218218
preconditionFailure("Invalid state: \(self.state)")
219-
219+
220220
case .waitingForInvocation:
221221
preconditionFailure("TODO: fixme")
222-
222+
223223
case .reportingStartupError(_, let error, let promise):
224224
self.state = .failed(error)
225225
return .failRuntime(error, startPomise: promise)
226-
226+
227227
case .reportingInvocationResult(let connection, let handler, true):
228228
self.state = .waitingForInvocation(connection, handler)
229229
return .none
230-
230+
231231
case .reportingInvocationResult(let connection, let handler, false):
232232
self.state = .waitingForInvocation(connection, handler)
233233
return .requestNextInvocation(connection.handler, succeedStartPromise: nil)
234-
234+
235235
case .failed:
236236
return .none
237237
}
238238
}
239-
239+
240240
mutating func errorResponseReceived(_ errorResponse: ErrorResponse) -> Action {
241241
switch self.state {
242242
case .initialized,
@@ -246,49 +246,45 @@ extension NewLambdaRuntime {
246246
.handlerCreationFailed,
247247
.executingInvocation:
248248
preconditionFailure("Invalid state: \(self.state)")
249-
249+
250250
case .waitingForInvocation:
251251
let error = LambdaRuntimeError.controlPlaneErrorResponse(errorResponse)
252252
self.state = .failed(error)
253253
return .failRuntime(error, startPomise: nil)
254-
254+
255255
case .reportingStartupError(_, let error, let promise):
256256
self.state = .failed(error)
257257
return .failRuntime(error, startPomise: promise)
258-
258+
259259
case .reportingInvocationResult:
260260
let error = LambdaRuntimeError.controlPlaneErrorResponse(errorResponse)
261261
self.state = .failed(error)
262262
return .failRuntime(error, startPomise: nil)
263-
263+
264264
case .failed:
265265
return .none
266266
}
267267
}
268-
269-
mutating func handlerError(_ error: Error) {
270-
271-
}
272-
273-
mutating func channelInactive() {
274-
275-
}
276-
268+
269+
mutating func handlerError(_: Error) {}
270+
271+
mutating func channelInactive() {}
272+
277273
mutating func invocationFinished(_ result: Result<ByteBuffer?, Error>) -> Action {
278274
switch self.state {
279275
case .initialized,
280-
.starting,
281-
.handlerCreated,
282-
.handlerCreationFailed,
283-
.connected,
284-
.waitingForInvocation,
285-
.reportingStartupError,
286-
.reportingInvocationResult:
276+
.starting,
277+
.handlerCreated,
278+
.handlerCreationFailed,
279+
.connected,
280+
.waitingForInvocation,
281+
.reportingStartupError,
282+
.reportingInvocationResult:
287283
preconditionFailure("Invalid state: \(self.state)")
288-
284+
289285
case .failed:
290286
return .none
291-
287+
292288
case .executingInvocation(let connection, let handler, let requestID):
293289
let pipelining = true
294290
self.state = .reportingInvocationResult(connection, handler, nextInvocationRequestPipelined: pipelining)

0 commit comments

Comments
 (0)