@@ -15,46 +15,52 @@ import NIO
15
15
16
16
/// Extension to the `Lambda` companion to enable execution of Lambdas that take and return `String` payloads.
17
17
extension 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.
19
25
///
20
26
/// - 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 ) {
22
28
self . run ( closure: closure)
23
29
}
24
30
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.
26
38
///
27
39
/// - 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 ) {
29
41
self . run ( closure: closure)
30
42
}
31
43
32
44
// for testing
33
45
@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) )
36
48
}
37
49
38
50
// for testing
39
51
@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) )
42
54
}
43
55
}
44
56
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 {
52
58
typealias In = String
53
59
typealias Out = String
54
60
55
- private let closure : StringLambdaClosure
61
+ private let closure : Lambda . StringClosure
56
62
57
- init ( _ closure: @escaping StringLambdaClosure ) {
63
+ init ( _ closure: @escaping Lambda . StringClosure ) {
58
64
self . closure = closure
59
65
}
60
66
@@ -63,13 +69,13 @@ internal struct StringLambdaClosureWrapper: LambdaHandler {
63
69
}
64
70
}
65
71
66
- internal struct StringVoidLambdaClosureWrapper : LambdaHandler {
72
+ internal struct StringVoidClosureWrapper : LambdaHandler {
67
73
typealias In = String
68
74
typealias Out = Void
69
75
70
- private let closure : StringVoidLambdaClosure
76
+ private let closure : Lambda . StringVoidClosure
71
77
72
- init ( _ closure: @escaping StringVoidLambdaClosure ) {
78
+ init ( _ closure: @escaping Lambda . StringVoidClosure ) {
73
79
self . closure = closure
74
80
}
75
81
@@ -78,8 +84,8 @@ internal struct StringVoidLambdaClosureWrapper: LambdaHandler {
78
84
}
79
85
}
80
86
81
- /// Implementation of a`ByteBuffer` to `String` encoding
82
87
public extension EventLoopLambdaHandler where In == String {
88
+ /// Implementation of a `ByteBuffer` to `String` decoding
83
89
func decode( buffer: ByteBuffer ) throws -> String {
84
90
var buffer = buffer
85
91
guard let string = buffer. readString ( length: buffer. readableBytes) else {
@@ -89,8 +95,8 @@ public extension EventLoopLambdaHandler where In == String {
89
95
}
90
96
}
91
97
92
- /// Implementation of `String` to `ByteBuffer` decoding
93
98
public extension EventLoopLambdaHandler where Out == String {
99
+ /// Implementation of `String` to `ByteBuffer` encoding
94
100
func encode( allocator: ByteBufferAllocator , value: String ) throws -> ByteBuffer ? {
95
101
// FIXME: reusable buffer
96
102
var buffer = allocator. buffer ( capacity: value. utf8. count)
0 commit comments