Skip to content

Commit ac52960

Browse files
authored
Initialize LambdaRuntime with concrete HandlerType + Docu fixes (#260)
1 parent cebcf04 commit ac52960

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

Sources/AWSLambdaRuntimeCore/LambdaContext.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public struct LambdaInitializationContext: _AWSLambdaSendable {
4343
/// `ByteBufferAllocator` to allocate `ByteBuffer`
4444
public let allocator: ByteBufferAllocator
4545

46-
/// `Terminator` to register shutdown operations
46+
/// ``LambdaTerminator`` to register shutdown operations
4747
public let terminator: LambdaTerminator
4848

4949
init(logger: Logger, eventLoop: EventLoop, allocator: ByteBufferAllocator, terminator: LambdaTerminator) {

Sources/AWSLambdaRuntimeCore/LambdaHandler.swift

+5-4
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public protocol EventLoopLambdaHandler: ByteBufferLambdaHandler {
119119
/// The `EventLoopFuture` should be completed with either a response of type `Output` or an `Error`
120120
func handle(_ event: Event, context: LambdaContext) -> EventLoopFuture<Output>
121121

122-
/// Encode a response of type `Output` to `ByteBuffer`
122+
/// Encode a response of type ``Output`` to `ByteBuffer`
123123
/// Concrete Lambda handlers implement this method to provide coding functionality.
124124
/// - parameters:
125125
/// - allocator: A `ByteBufferAllocator` to help allocate the `ByteBuffer`.
@@ -128,7 +128,7 @@ public protocol EventLoopLambdaHandler: ByteBufferLambdaHandler {
128128
/// - Returns: A `ByteBuffer` with the encoded version of the `value`.
129129
func encode(allocator: ByteBufferAllocator, value: Output) throws -> ByteBuffer?
130130

131-
/// Decode a`ByteBuffer` to a request or event of type `Event`
131+
/// Decode a `ByteBuffer` to a request or event of type ``Event``
132132
/// Concrete Lambda handlers implement this method to provide coding functionality.
133133
///
134134
/// - parameters:
@@ -139,7 +139,7 @@ public protocol EventLoopLambdaHandler: ByteBufferLambdaHandler {
139139
}
140140

141141
extension EventLoopLambdaHandler {
142-
/// Driver for `ByteBuffer` -> `Event` decoding and `Output` -> `ByteBuffer` encoding
142+
/// Driver for `ByteBuffer` -> ``Event`` decoding and ``Output`` -> `ByteBuffer` encoding
143143
@inlinable
144144
public func handle(_ event: ByteBuffer, context: LambdaContext) -> EventLoopFuture<ByteBuffer?> {
145145
let input: Event
@@ -169,7 +169,8 @@ extension EventLoopLambdaHandler where Output == Void {
169169

170170
// MARK: - ByteBufferLambdaHandler
171171

172-
/// An `EventLoopFuture` based processing protocol for a Lambda that takes a `ByteBuffer` and returns a `ByteBuffer?` asynchronously.
172+
/// An `EventLoopFuture` based processing protocol for a Lambda that takes a `ByteBuffer` and returns
173+
/// an optional `ByteBuffer` asynchronously.
173174
///
174175
/// - note: This is a low level protocol designed to power the higher level ``EventLoopLambdaHandler`` and
175176
/// ``LambdaHandler`` based APIs.

Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift

+4-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import NIOCore
1818

1919
/// `LambdaRuntime` manages the Lambda process lifecycle.
2020
///
21-
/// - note: It is intended to be used within a single `EventLoop`. For this reason this class is not thread safe.
21+
/// Use this API, if you build a higher level web framework which shall be able to run inside the Lambda environment.
2222
public final class LambdaRuntime<Handler: ByteBufferLambdaHandler> {
2323
private let eventLoop: EventLoop
2424
private let shutdownPromise: EventLoopPromise<Int>
@@ -35,9 +35,10 @@ public final class LambdaRuntime<Handler: ByteBufferLambdaHandler> {
3535
/// Create a new `LambdaRuntime`.
3636
///
3737
/// - parameters:
38+
/// - handlerType: The ``ByteBufferLambdaHandler`` type the `LambdaRuntime` shall create and manage
3839
/// - eventLoop: An `EventLoop` to run the Lambda on.
3940
/// - logger: A `Logger` to log the Lambda events.
40-
public convenience init(eventLoop: EventLoop, logger: Logger) {
41+
public convenience init(_ handlerType: Handler.Type, eventLoop: EventLoop, logger: Logger) {
4142
self.init(eventLoop: eventLoop, logger: logger, configuration: .init())
4243
}
4344

@@ -114,8 +115,7 @@ public final class LambdaRuntime<Handler: ByteBufferLambdaHandler> {
114115

115116
// MARK: - Private
116117

117-
#if DEBUG
118-
/// Begin the `LambdaRuntime` shutdown. Only needed for debugging purposes, hence behind a `DEBUG` flag.
118+
/// Begin the `LambdaRuntime` shutdown.
119119
public func shutdown() {
120120
// make this method thread safe by dispatching onto the eventloop
121121
self.eventLoop.execute {
@@ -126,7 +126,6 @@ public final class LambdaRuntime<Handler: ByteBufferLambdaHandler> {
126126
}
127127
}
128128
}
129-
#endif
130129

131130
private func markShutdown() {
132131
self.state = .shutdown

Tests/AWSLambdaRuntimeCoreTests/LambdaRuntimeTest.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class LambdaRuntimeTest: XCTestCase {
2929

3030
let eventLoop = eventLoopGroup.next()
3131
let logger = Logger(label: "TestLogger")
32-
let runtime = LambdaRuntime<StartupErrorHandler>(eventLoop: eventLoop, logger: logger)
32+
let runtime = LambdaRuntime(StartupErrorHandler.self, eventLoop: eventLoop, logger: logger)
3333

3434
// eventLoop.submit in this case returns an EventLoopFuture<EventLoopFuture<ByteBufferHandler>>
3535
// which is why we need `wait().wait()`
@@ -51,7 +51,7 @@ class LambdaRuntimeTest: XCTestCase {
5151

5252
let eventLoop = eventLoopGroup.next()
5353
let logger = Logger(label: "TestLogger")
54-
let runtime = LambdaRuntime<EchoHandler>(eventLoop: eventLoop, logger: logger)
54+
let runtime = LambdaRuntime(EchoHandler.self, eventLoop: eventLoop, logger: logger)
5555

5656
XCTAssertNoThrow(_ = try eventLoop.flatSubmit { runtime.start() }.wait())
5757
XCTAssertThrowsError(_ = try runtime.shutdownFuture.wait()) {
@@ -101,7 +101,7 @@ class LambdaRuntimeTest: XCTestCase {
101101

102102
let eventLoop = eventLoopGroup.next()
103103
let logger = Logger(label: "TestLogger")
104-
let runtime = LambdaRuntime<ShutdownErrorHandler>(eventLoop: eventLoop, logger: logger)
104+
let runtime = LambdaRuntime(ShutdownErrorHandler.self, eventLoop: eventLoop, logger: logger)
105105

106106
XCTAssertNoThrow(try eventLoop.flatSubmit { runtime.start() }.wait())
107107
XCTAssertThrowsError(try runtime.shutdownFuture.wait()) { error in

0 commit comments

Comments
 (0)