Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some documentation fixes #260

Merged
merged 2 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/AWSLambdaRuntimeCore/LambdaContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public struct LambdaInitializationContext: _AWSLambdaSendable {
/// `ByteBufferAllocator` to allocate `ByteBuffer`
public let allocator: ByteBufferAllocator

/// `Terminator` to register shutdown operations
/// ``LambdaTerminator`` to register shutdown operations
public let terminator: LambdaTerminator

init(logger: Logger, eventLoop: EventLoop, allocator: ByteBufferAllocator, terminator: LambdaTerminator) {
Expand Down
9 changes: 5 additions & 4 deletions Sources/AWSLambdaRuntimeCore/LambdaHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public protocol EventLoopLambdaHandler: ByteBufferLambdaHandler {
/// The `EventLoopFuture` should be completed with either a response of type `Output` or an `Error`
func handle(_ event: Event, context: LambdaContext) -> EventLoopFuture<Output>

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

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

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

// MARK: - ByteBufferLambdaHandler

/// An `EventLoopFuture` based processing protocol for a Lambda that takes a `ByteBuffer` and returns a `ByteBuffer?` asynchronously.
/// An `EventLoopFuture` based processing protocol for a Lambda that takes a `ByteBuffer` and returns
/// an optional `ByteBuffer` asynchronously.
///
/// - note: This is a low level protocol designed to power the higher level ``EventLoopLambdaHandler`` and
/// ``LambdaHandler`` based APIs.
Expand Down
9 changes: 4 additions & 5 deletions Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import NIOCore

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

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

// MARK: - Private

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

private func markShutdown() {
self.state = .shutdown
Expand Down
6 changes: 3 additions & 3 deletions Tests/AWSLambdaRuntimeCoreTests/LambdaRuntimeTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class LambdaRuntimeTest: XCTestCase {

let eventLoop = eventLoopGroup.next()
let logger = Logger(label: "TestLogger")
let runtime = LambdaRuntime<StartupErrorHandler>(eventLoop: eventLoop, logger: logger)
let runtime = LambdaRuntime(StartupErrorHandler.self, eventLoop: eventLoop, logger: logger)

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

let eventLoop = eventLoopGroup.next()
let logger = Logger(label: "TestLogger")
let runtime = LambdaRuntime<EchoHandler>(eventLoop: eventLoop, logger: logger)
let runtime = LambdaRuntime(EchoHandler.self, eventLoop: eventLoop, logger: logger)

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

let eventLoop = eventLoopGroup.next()
let logger = Logger(label: "TestLogger")
let runtime = LambdaRuntime<ShutdownErrorHandler>(eventLoop: eventLoop, logger: logger)
let runtime = LambdaRuntime(ShutdownErrorHandler.self, eventLoop: eventLoop, logger: logger)

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