Skip to content

Commit 5ed63d5

Browse files
committed
Remove NewLambda.swift and merge into Lambda.swift
1 parent 85b938e commit 5ed63d5

File tree

2 files changed

+34
-52
lines changed

2 files changed

+34
-52
lines changed

Sources/AWSLambdaRuntimeCore/Lambda.swift

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
import Dispatch
1516
import Logging
1617
import NIOCore
1718
import NIOPosix
@@ -28,7 +29,39 @@ import ucrt
2829
#error("Unsupported platform")
2930
#endif
3031

31-
enum Lambda {}
32+
enum Lambda {
33+
package static func runLoop<RuntimeClient: LambdaRuntimeClientProtocol, Handler>(
34+
runtimeClient: RuntimeClient,
35+
handler: Handler,
36+
logger: Logger
37+
) async throws where Handler: StreamingLambdaHandler {
38+
var handler = handler
39+
40+
while !Task.isCancelled {
41+
let (invocation, writer) = try await runtimeClient.nextInvocation()
42+
43+
do {
44+
try await handler.handle(
45+
invocation.event,
46+
responseWriter: writer,
47+
context: NewLambdaContext(
48+
requestID: invocation.metadata.requestID,
49+
traceID: invocation.metadata.traceID,
50+
invokedFunctionARN: invocation.metadata.invokedFunctionARN,
51+
deadline: DispatchWallTime(millisSinceEpoch: invocation.metadata.deadlineInMillisSinceEpoch),
52+
logger: logger
53+
)
54+
)
55+
} catch {
56+
try await writer.reportError(error)
57+
continue
58+
}
59+
}
60+
}
61+
62+
/// The default EventLoop the Lambda is scheduled on.
63+
package static var defaultEventLoop: any EventLoop = NIOSingletons.posixEventLoopGroup.next()
64+
}
3265

3366
// MARK: - Public API
3467

Sources/AWSLambdaRuntimeCore/NewLambda.swift

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)