Skip to content

Commit a00a654

Browse files
committed
Remove DetachedTasks
1 parent 7a8c0f2 commit a00a654

File tree

4 files changed

+5
-219
lines changed

4 files changed

+5
-219
lines changed

Sources/AWSLambdaRuntimeCore/DetachedTasks.swift

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

Sources/AWSLambdaRuntimeCore/LambdaContext.swift

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable {
8181
let logger: Logger
8282
let eventLoop: EventLoop
8383
let allocator: ByteBufferAllocator
84-
let tasks: DetachedTasksContainer
8584

8685
init(
8786
requestID: String,
@@ -92,8 +91,7 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable {
9291
clientContext: String?,
9392
logger: Logger,
9493
eventLoop: EventLoop,
95-
allocator: ByteBufferAllocator,
96-
tasks: DetachedTasksContainer
94+
allocator: ByteBufferAllocator
9795
) {
9896
self.requestID = requestID
9997
self.traceID = traceID
@@ -104,7 +102,6 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable {
104102
self.logger = logger
105103
self.eventLoop = eventLoop
106104
self.allocator = allocator
107-
self.tasks = tasks
108105
}
109106
}
110107

@@ -182,13 +179,7 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable {
182179
clientContext: clientContext,
183180
logger: logger,
184181
eventLoop: eventLoop,
185-
allocator: allocator,
186-
tasks: DetachedTasksContainer(
187-
context: DetachedTasksContainer.Context(
188-
eventLoop: eventLoop,
189-
logger: logger
190-
)
191-
)
182+
allocator: allocator
192183
)
193184
}
194185

@@ -200,22 +191,6 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable {
200191
return .milliseconds(remaining)
201192
}
202193

203-
var tasks: DetachedTasksContainer {
204-
self.storage.tasks
205-
}
206-
207-
/// Registers a background task that continues running after the synchronous invocation has completed.
208-
/// This is useful for tasks like flushing metrics or performing clean-up operations without delaying the response.
209-
///
210-
/// - Parameter body: An asynchronous closure that performs the background task.
211-
/// - Warning: You will be billed for the milliseconds of Lambda execution time until the very last
212-
/// background task is finished.
213-
public func detachedBackgroundTask(_ body: @escaping @Sendable () async -> Void) {
214-
Task {
215-
await self.tasks.detached(task: body)
216-
}
217-
}
218-
219194
public var debugDescription: String {
220195
"\(Self.self)(requestID: \(self.requestID), traceID: \(self.traceID), invokedFunctionARN: \(self.invokedFunctionARN), cognitoIdentity: \(self.cognitoIdentity ?? "nil"), clientContext: \(self.clientContext ?? "nil"), deadline: \(self.deadline))"
221196
}

Sources/AWSLambdaRuntimeCore/LambdaRunner.swift

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,28 +97,13 @@ final class LambdaRunner {
9797
if case .failure(let error) = result {
9898
logger.warning("lambda handler returned an error: \(error)")
9999
}
100-
return (invocation, result, context)
100+
return (invocation, result)
101101
}
102-
}.flatMap { invocation, result, context in
102+
}.flatMap { invocation, result in
103103
// 3. report results to runtime engine
104-
self.runtimeClient.reportResults(logger: logger, invocation: invocation, result: result).peekError {
105-
error in
104+
self.runtimeClient.reportResults(logger: logger, invocation: invocation, result: result).peekError { error in
106105
logger.error("could not report results to lambda runtime engine: \(error)")
107-
// To discuss:
108-
// Do we want to await the tasks in this case?
109-
let promise = context.eventLoop.makePromise(of: Void.self)
110-
promise.completeWithTask {
111-
try await context.tasks.awaitAll().get()
112-
}
113-
return promise.futureResult
114-
}.map { _ in context }
115-
}
116-
.flatMap { (context: LambdaContext) -> EventLoopFuture<Void> in
117-
let promise = context.eventLoop.makePromise(of: Void.self)
118-
promise.completeWithTask {
119-
try await context.tasks.awaitAll().get()
120106
}
121-
return promise.futureResult
122107
}
123108
}
124109

Tests/AWSLambdaRuntimeCoreTests/DetachedTasksTests.swift

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

0 commit comments

Comments
 (0)