Skip to content

Commit cc6f636

Browse files
committed
Lambda factory as a protocol requirement.
# Conflicts: # Sources/AWSLambdaRuntimeCore/Lambda.swift # Sources/AWSLambdaRuntimeCore/LambdaHandler.swift
1 parent 490c546 commit cc6f636

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

Sources/AWSLambdaRuntimeCore/Lambda.swift

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@ public enum Lambda {
3232
return String(cString: value)
3333
}
3434

35-
// for testing and internal use
36-
internal static func run<Handler: ByteBufferLambdaHandler>(
37-
configuration: Configuration = .init(),
38-
handlerType: Handler.Type
39-
) -> Result<Int, Error> {
40-
let _run = { (configuration: Configuration, handlerType: Handler.Type) -> Result<Int, Error> in
35+
/// Run a Lambda defined by implementing the ``ByteBufferLambdaHandler`` protocol.
36+
/// The Runtime will manage the Lambdas application lifecycle automatically. It will invoke the
37+
/// ``ByteBufferLambdaHandler/factory(context:)`` to create a new Handler.
38+
///
39+
/// - parameters:
40+
/// - factory: A `ByteBufferLambdaHandler` factory.
41+
///
42+
/// - note: This is a blocking operation that will run forever, as its lifecycle is managed by the AWS Lambda Runtime Engine.
43+
internal static func run<Handler: ByteBufferLambdaHandler>(configuration: Configuration = .init(), handlerType: Handler.Type) -> Result<Int, Error> {
44+
let _run = { (configuration: Configuration) -> Result<Int, Error> in
4145
Backtrace.install()
4246
var logger = Logger(label: "Lambda")
4347
logger.logLevel = configuration.general.logLevel
@@ -76,17 +80,16 @@ public enum Lambda {
7680
if Lambda.env("LOCAL_LAMBDA_SERVER_ENABLED").flatMap(Bool.init) ?? false {
7781
do {
7882
return try Lambda.withLocalServer {
79-
_run(configuration, handlerType)
83+
_run(configuration)
8084
}
8185
} catch {
8286
return .failure(error)
8387
}
8488
} else {
85-
return _run(configuration, handlerType)
89+
return _run(configuration)
8690
}
8791
#else
8892
return _run(configuration, factory)
8993
#endif
9094
}
91-
9295
}

Sources/AWSLambdaRuntimeCore/LambdaRunner.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extension Lambda {
4141
let context = InitializationContext(logger: logger,
4242
eventLoop: self.eventLoop,
4343
allocator: self.allocator)
44-
return Handler.makeHandler(context: context)
44+
return Handler.factory(context: context)
4545
// Hopping back to "our" EventLoop is important in case the factory returns a future
4646
// that originated from a foreign EventLoop/EventLoopGroup.
4747
// This can happen if the factory uses a library (let's say a database client) that manages its own threads/loops

0 commit comments

Comments
 (0)