@@ -15,46 +15,52 @@ import NIO
1515
1616/// Extension to the `Lambda` companion to enable execution of Lambdas that take and return `String` payloads.
1717extension Lambda {
18- /// Run a Lambda defined by implementing the `StringLambdaClosure` function.
18+ /// An asynchronous Lambda Closure that takes a `String` and returns a `Result<String, Error>` via a completion handler.
19+ public typealias StringClosure = ( Lambda . Context , String , @escaping ( Result < String , Error > ) -> Void ) -> Void
20+
21+ /// Run a Lambda defined by implementing the `StringClosure` function.
22+ ///
23+ /// - parameters:
24+ /// - closure: `StringClosure` based Lambda.
1925 ///
2026 /// - note: This is a blocking operation that will run forever, as its lifecycle is managed by the AWS Lambda Runtime Engine.
21- public static func run( _ closure: @escaping StringLambdaClosure ) {
27+ public static func run( _ closure: @escaping StringClosure ) {
2228 self . run ( closure: closure)
2329 }
2430
25- /// Run a Lambda defined by implementing the `StringVoidLambdaClosure` function.
31+ /// An asynchronous Lambda Closure that takes a `String` and returns a `Result<Void, Error>` via a completion handler.
32+ public typealias StringVoidClosure = ( Lambda . Context , String , @escaping ( Result < Void , Error > ) -> Void ) -> Void
33+
34+ /// Run a Lambda defined by implementing the `StringVoidClosure` function.
35+ ///
36+ /// - parameters:
37+ /// - closure: `StringVoidClosure` based Lambda.
2638 ///
2739 /// - note: This is a blocking operation that will run forever, as its lifecycle is managed by the AWS Lambda Runtime Engine.
28- public static func run( _ closure: @escaping StringVoidLambdaClosure ) {
40+ public static func run( _ closure: @escaping StringVoidClosure ) {
2941 self . run ( closure: closure)
3042 }
3143
3244 // for testing
3345 @discardableResult
34- internal static func run( configuration: Configuration = . init( ) , closure: @escaping StringLambdaClosure ) -> Result < Int , Error > {
35- self . run ( configuration: configuration, handler: StringLambdaClosureWrapper ( closure) )
46+ internal static func run( configuration: Configuration = . init( ) , closure: @escaping StringClosure ) -> Result < Int , Error > {
47+ self . run ( configuration: configuration, handler: StringClosureWrapper ( closure) )
3648 }
3749
3850 // for testing
3951 @discardableResult
40- internal static func run( configuration: Configuration = . init( ) , closure: @escaping StringVoidLambdaClosure ) -> Result < Int , Error > {
41- self . run ( configuration: configuration, handler: StringVoidLambdaClosureWrapper ( closure) )
52+ internal static func run( configuration: Configuration = . init( ) , closure: @escaping StringVoidClosure ) -> Result < Int , Error > {
53+ self . run ( configuration: configuration, handler: StringVoidClosureWrapper ( closure) )
4254 }
4355}
4456
45- /// A processing closure for a Lambda that takes a `String` and returns a `Result<String, Error>` via a `CompletionHandler` asynchronously.
46- public typealias StringLambdaClosure = ( Lambda . Context , String , @escaping ( Result < String , Error > ) -> Void ) -> Void
47-
48- /// A processing closure for a Lambda that takes a `String` and returns a `Result<Void, Error>` via a `CompletionHandler` asynchronously.
49- public typealias StringVoidLambdaClosure = ( Lambda . Context , String , @escaping ( Result < Void , Error > ) -> Void ) -> Void
50-
51- internal struct StringLambdaClosureWrapper : LambdaHandler {
57+ internal struct StringClosureWrapper : LambdaHandler {
5258 typealias In = String
5359 typealias Out = String
5460
55- private let closure : StringLambdaClosure
61+ private let closure : Lambda . StringClosure
5662
57- init ( _ closure: @escaping StringLambdaClosure ) {
63+ init ( _ closure: @escaping Lambda . StringClosure ) {
5864 self . closure = closure
5965 }
6066
@@ -63,13 +69,13 @@ internal struct StringLambdaClosureWrapper: LambdaHandler {
6369 }
6470}
6571
66- internal struct StringVoidLambdaClosureWrapper : LambdaHandler {
72+ internal struct StringVoidClosureWrapper : LambdaHandler {
6773 typealias In = String
6874 typealias Out = Void
6975
70- private let closure : StringVoidLambdaClosure
76+ private let closure : Lambda . StringVoidClosure
7177
72- init ( _ closure: @escaping StringVoidLambdaClosure ) {
78+ init ( _ closure: @escaping Lambda . StringVoidClosure ) {
7379 self . closure = closure
7480 }
7581
@@ -78,8 +84,8 @@ internal struct StringVoidLambdaClosureWrapper: LambdaHandler {
7884 }
7985}
8086
81- /// Implementation of a`ByteBuffer` to `String` encoding
8287public extension EventLoopLambdaHandler where In == String {
88+ /// Implementation of a `ByteBuffer` to `String` decoding
8389 func decode( buffer: ByteBuffer ) throws -> String {
8490 var buffer = buffer
8591 guard let string = buffer. readString ( length: buffer. readableBytes) else {
@@ -89,8 +95,8 @@ public extension EventLoopLambdaHandler where In == String {
8995 }
9096}
9197
92- /// Implementation of `String` to `ByteBuffer` decoding
9398public extension EventLoopLambdaHandler where Out == String {
99+ /// Implementation of `String` to `ByteBuffer` encoding
94100 func encode( allocator: ByteBufferAllocator , value: String ) throws -> ByteBuffer ? {
95101 // FIXME: reusable buffer
96102 var buffer = allocator. buffer ( capacity: value. utf8. count)
0 commit comments