Skip to content

Commit bbd6382

Browse files
committed
Offload sync lambda factory
1 parent c61a650 commit bbd6382

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

Sources/AWSLambdaRuntime/Lambda.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,15 @@ public enum Lambda {
7272
@discardableResult
7373
internal static func run(configuration: Configuration = .init(), factory: @escaping (EventLoop) throws -> Handler) -> Result<Int, Error> {
7474
self.run(configuration: configuration, factory: { eventloop -> EventLoopFuture<Handler> in
75-
do {
76-
let handler = try factory(eventloop)
77-
return eventloop.makeSucceededFuture(handler)
78-
} catch {
79-
return eventloop.makeFailedFuture(error)
75+
let promise = eventloop.makePromise(of: Handler.self)
76+
Lambda.defaultOffloadQueue.async {
77+
do {
78+
promise.succeed(try factory(eventloop))
79+
} catch {
80+
promise.fail(error)
81+
}
8082
}
83+
return promise.futureResult
8184
})
8285
}
8386

Sources/AWSLambdaRuntime/LambdaHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public protocol LambdaHandler: EventLoopLambdaHandler {
3939
func handle(context: Lambda.Context, payload: In, callback: @escaping (Result<Out, Error>) -> Void)
4040
}
4141

42-
private extension Lambda {
42+
internal extension Lambda {
4343
static let defaultOffloadQueue = DispatchQueue(label: "LambdaHandler.offload")
4444
}
4545

0 commit comments

Comments
 (0)