File tree Expand file tree Collapse file tree 2 files changed +34
-52
lines changed
Sources/AWSLambdaRuntimeCore Expand file tree Collapse file tree 2 files changed +34
-52
lines changed Original file line number Diff line number Diff line change 12
12
//
13
13
//===----------------------------------------------------------------------===//
14
14
15
+ import Dispatch
15
16
import Logging
16
17
import NIOCore
17
18
import NIOPosix
@@ -28,7 +29,39 @@ import ucrt
28
29
#error("Unsupported platform")
29
30
#endif
30
31
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
+ }
32
65
33
66
// MARK: - Public API
34
67
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments