Skip to content

Commit 501bc6e

Browse files
committed
Drop event label from handle method in LambdaHandlers
1 parent dbd675d commit 501bc6e

File tree

15 files changed

+40
-40
lines changed

15 files changed

+40
-40
lines changed

Examples/LambdaFunctions/Sources/Benchmark/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct BenchmarkHandler: EventLoopLambdaHandler {
2525
typealias In = String
2626
typealias Out = String
2727

28-
func handle(event: String, context: Lambda.Context) -> EventLoopFuture<String> {
28+
func handle(_ event: String, context: Lambda.Context) -> EventLoopFuture<String> {
2929
context.eventLoop.makeSucceededFuture("hello, world!")
3030
}
3131
}

Examples/LambdaFunctions/Sources/CurrencyExchange/CurrencyExchangeHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct CurrencyExchangeHandler: LambdaHandler {
3535
self.calculator = ExchangeRatesCalculator()
3636
}
3737

38-
func handle(event: Request, context: Lambda.Context) async throws -> [Exchange] {
38+
func handle(_ event: Request, context: Lambda.Context) async throws -> [Exchange] {
3939
try await withCheckedThrowingContinuation { continuation in
4040
self.calculator.run(logger: context.logger) { result in
4141
switch result {

Examples/LambdaFunctions/Sources/ErrorHandling/ErrorsHappenHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct ErrorsHappenHandler: LambdaHandler {
2323

2424
init(context: Lambda.InitializationContext) async throws {}
2525

26-
func handle(event request: Request, context: Lambda.Context) async throws -> Response {
26+
func handle(_ request: Request, context: Lambda.Context) async throws -> Response {
2727
// switch over the error type "requested" by the request, and trigger such error accordingly
2828
switch request.error {
2929
// no error here!

Examples/LambdaFunctions/Sources/HelloWorld/HelloWorldHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct HelloWorldHandler: LambdaHandler {
2424
// setup your resources that you want to reuse here.
2525
}
2626

27-
func handle(event: String, context: Lambda.Context) async throws -> String {
27+
func handle(_ event: String, context: Lambda.Context) async throws -> String {
2828
"hello, world"
2929
}
3030
}

Examples/LocalDebugging/MyLambda/Sources/MyLambda/MyLambdaHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct MyLambdaHandler: LambdaHandler {
2626
// setup your resources that you want to reuse for every invocation here.
2727
}
2828

29-
func handle(event request: Request, context: Lambda.Context) async throws -> Response {
29+
func handle(_ request: Request, context: Lambda.Context) async throws -> Response {
3030
// TODO: something useful
3131
Response(message: "Hello, \(request.name)!")
3232
}

Sources/AWSLambdaRuntimeCore/LambdaHandler.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ public protocol LambdaHandler: EventLoopLambdaHandler {
3838
/// - context: Runtime `Context`.
3939
///
4040
/// - Returns: A Lambda result ot type `Out`.
41-
func handle(event: In, context: Lambda.Context) async throws -> Out
41+
func handle(_ event: In, context: Lambda.Context) async throws -> Out
4242
}
4343

4444
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
4545
extension LambdaHandler {
46-
public func handle(event: In, context: Lambda.Context) -> EventLoopFuture<Out> {
46+
public func handle(_ event: In, context: Lambda.Context) -> EventLoopFuture<Out> {
4747
let promise = context.eventLoop.makePromise(of: Out.self)
4848
promise.completeWithTask {
49-
try await self.handle(event: event, context: context)
49+
try await self.handle(event, context: context)
5050
}
5151
return promise.futureResult
5252
}
@@ -82,7 +82,7 @@ public protocol EventLoopLambdaHandler: ByteBufferLambdaHandler {
8282
///
8383
/// - Returns: An `EventLoopFuture` to report the result of the Lambda back to the runtime engine.
8484
/// The `EventLoopFuture` should be completed with either a response of type `Out` or an `Error`
85-
func handle(event: In, context: Lambda.Context) -> EventLoopFuture<Out>
85+
func handle(_ event: In, context: Lambda.Context) -> EventLoopFuture<Out>
8686

8787
/// Encode a response of type `Out` to `ByteBuffer`
8888
/// Concrete Lambda handlers implement this method to provide coding functionality.
@@ -106,15 +106,15 @@ public protocol EventLoopLambdaHandler: ByteBufferLambdaHandler {
106106
extension EventLoopLambdaHandler {
107107
/// Driver for `ByteBuffer` -> `In` decoding and `Out` -> `ByteBuffer` encoding
108108
@inlinable
109-
public func handle(event: ByteBuffer, context: Lambda.Context) -> EventLoopFuture<ByteBuffer?> {
109+
public func handle(_ event: ByteBuffer, context: Lambda.Context) -> EventLoopFuture<ByteBuffer?> {
110110
let input: In
111111
do {
112112
input = try self.decode(buffer: event)
113113
} catch {
114114
return context.eventLoop.makeFailedFuture(CodecError.requestDecoding(error))
115115
}
116116

117-
return self.handle(event: input, context: context).flatMapThrowing { output in
117+
return self.handle(input, context: context).flatMapThrowing { output in
118118
do {
119119
return try self.encode(allocator: context.allocator, value: output)
120120
} catch {
@@ -148,7 +148,7 @@ public protocol ByteBufferLambdaHandler {
148148
///
149149
/// - Returns: An `EventLoopFuture` to report the result of the Lambda back to the runtime engine.
150150
/// The `EventLoopFuture` should be completed with either a response encoded as `ByteBuffer` or an `Error`
151-
func handle(event: ByteBuffer, context: Lambda.Context) -> EventLoopFuture<ByteBuffer?>
151+
func handle(_ event: ByteBuffer, context: Lambda.Context) -> EventLoopFuture<ByteBuffer?>
152152

153153
/// Clean up the Lambda resources asynchronously.
154154
/// Concrete Lambda handlers implement this method to shutdown resources like `HTTPClient`s and database connections.

Sources/AWSLambdaRuntimeCore/LambdaRunner.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ extension Lambda {
6262
self.isGettingNextInvocation = true
6363
return self.runtimeClient.getNextInvocation(logger: logger).peekError { error in
6464
logger.error("could not fetch work from lambda runtime engine: \(error)")
65-
}.flatMap { invocation, event in
65+
}.flatMap { invocation, bytes in
6666
// 2. send invocation to handler
6767
self.isGettingNextInvocation = false
6868
let context = Context(logger: logger,
6969
eventLoop: self.eventLoop,
7070
allocator: self.allocator,
7171
invocation: invocation)
7272
logger.debug("sending invocation to lambda handler \(handler)")
73-
return handler.handle(event: event, context: context)
73+
return handler.handle(bytes, context: context)
7474
// Hopping back to "our" EventLoop is important in case the handler returns a future that
7575
// originiated from a foreign EventLoop/EventLoopGroup.
7676
// This can happen if the handler uses a library (lets say a DB client) that manages its own threads/loops

Sources/AWSLambdaTesting/Lambda+Testing.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ extension Lambda {
9797
let handler = try promise.futureResult.wait()
9898

9999
return try eventLoop.flatSubmit {
100-
handler.handle(event: event, context: context)
100+
handler.handle(event, context: context)
101101
}.wait()
102102
}
103103
}

Sources/CodableSample/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct Handler: EventLoopLambdaHandler {
2929
typealias In = Request
3030
typealias Out = Response
3131

32-
func handle(event: Request, context: Lambda.Context) -> EventLoopFuture<Response> {
32+
func handle(_ event: Request, context: Lambda.Context) -> EventLoopFuture<Response> {
3333
// as an example, respond with the input event's reversed body
3434
context.eventLoop.makeSucceededFuture(Response(body: String(event.body.reversed())))
3535
}

Sources/StringSample/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct Handler: EventLoopLambdaHandler {
2020
typealias In = String
2121
typealias Out = String
2222

23-
func handle(event: String, context: Lambda.Context) -> EventLoopFuture<String> {
23+
func handle(_ event: String, context: Lambda.Context) -> EventLoopFuture<String> {
2424
// as an example, respond with the event's reversed body
2525
context.eventLoop.makeSucceededFuture(String(event.reversed()))
2626
}

0 commit comments

Comments
 (0)