Skip to content

Commit 45d34c4

Browse files
committed
Review comments.
1 parent 48afb03 commit 45d34c4

File tree

4 files changed

+9
-30
lines changed

4 files changed

+9
-30
lines changed

Sources/AWSLambdaRuntimeCore/HTTPClient.swift

+4-5
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ internal final class HTTPClient {
6565
// TODO: cap reconnect attempt
6666
private func execute(_ request: Request, validate: Bool = true) -> EventLoopFuture<Response> {
6767
if validate {
68-
precondition(self.executing == false)
68+
precondition(self.executing == false, "expecting single request at a time")
6969
self.executing = true
7070
}
7171

@@ -83,7 +83,7 @@ internal final class HTTPClient {
8383

8484
let promise = channel.eventLoop.makePromise(of: Response.self)
8585
promise.futureResult.whenComplete { _ in
86-
precondition(self.executing == true)
86+
precondition(self.executing == true, "invalid execution state")
8787
self.executing = false
8888
}
8989
let wrapper = HTTPRequestWrapper(request: request, promise: promise)
@@ -306,10 +306,9 @@ private final class UnaryHandler: ChannelDuplexHandler {
306306
func triggerUserOutboundEvent(context: ChannelHandlerContext, event: Any, promise: EventLoopPromise<Void>?) {
307307
switch event {
308308
case is RequestCancelEvent:
309-
guard self.pending != nil else {
310-
return
309+
if self.pending != nil {
310+
self.completeWith(.failure(HTTPClient.Errors.cancelled))
311311
}
312-
self.completeWith(.failure(HTTPClient.Errors.cancelled))
313312
default:
314313
context.triggerUserOutboundEvent(event, promise: promise)
315314
}

Sources/AWSLambdaRuntimeCore/LambdaLifecycle.swift

+5-21
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ extension Lambda {
2727
private let configuration: Configuration
2828
private let factory: HandlerFactory
2929

30-
private var _state = State.idle
31-
private let stateLock = Lock()
30+
private var state = State.idle
3231

3332
/// Create a new `Lifecycle`.
3433
///
@@ -88,11 +87,11 @@ extension Lambda {
8887
public func shutdown() {
8988
// make this method thread safe by dispatching onto the eventloop
9089
self.eventLoop.execute {
91-
guard case .active(let runner, _) = self.state else {
92-
return
93-
}
90+
let oldState = self.state
9491
self.state = .shuttingdown
95-
runner.cancelWaitingForNextInvocation()
92+
if case .active(let runner, _) = oldState {
93+
runner.cancelWaitingForNextInvocation()
94+
}
9695
}
9796
}
9897
#endif
@@ -130,21 +129,6 @@ extension Lambda {
130129
_run(0)
131130
}
132131

133-
private var state: State {
134-
get {
135-
self.stateLock.withLock {
136-
self._state
137-
}
138-
}
139-
set {
140-
self.stateLock.withLockVoid {
141-
precondition(newValue.order > self._state.order, "invalid state \(newValue) after \(self._state)")
142-
self._state = newValue
143-
}
144-
self.logger.debug("lambda lifecycle state: \(newValue)")
145-
}
146-
}
147-
148132
private enum State {
149133
case idle
150134
case initializing

Sources/AWSLambdaRuntimeCore/LambdaRunner.swift

-2
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,12 @@ extension Lambda {
7474
}
7575
}
7676

77-
#if DEBUG
7877
/// cancels the current run, if we are waiting for next invocation (long poll from Lambda control plane)
7978
/// only needed for debugging purposes.
8079
func cancelWaitingForNextInvocation() {
8180
guard self.isGettingNextInvocation else { return }
8281
self.runtimeClient.cancel()
8382
}
84-
#endif
8583
}
8684
}
8785

Sources/AWSLambdaRuntimeCore/LambdaRuntimeClient.swift

-2
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,10 @@ extension Lambda {
115115
}
116116
}
117117

118-
#if DEBUG
119118
/// Cancels the current request, if one is running. Only needed for debugging purposes
120119
func cancel() {
121120
self.httpClient.cancel()
122121
}
123-
#endif
124122
}
125123
}
126124

0 commit comments

Comments
 (0)