Skip to content

Commit ce91afb

Browse files
committed
Offload sync lambda factory
1 parent c6eeeb1 commit ce91afb

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

Sources/AWSLambdaRuntimeCore/Lambda.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,15 @@ public enum Lambda {
8080
@discardableResult
8181
internal static func run(configuration: Configuration = .init(), factory: @escaping (EventLoop) throws -> Handler) -> Result<Int, Error> {
8282
self.run(configuration: configuration, factory: { eventloop -> EventLoopFuture<Handler> in
83-
do {
84-
let handler = try factory(eventloop)
85-
return eventloop.makeSucceededFuture(handler)
86-
} catch {
87-
return eventloop.makeFailedFuture(error)
83+
let promise = eventloop.makePromise(of: Handler.self)
84+
Lambda.defaultOffloadQueue.async {
85+
do {
86+
promise.succeed(try factory(eventloop))
87+
} catch {
88+
promise.fail(error)
89+
}
8890
}
91+
return promise.futureResult
8992
})
9093
}
9194

Sources/AWSLambdaRuntimeCore/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)