Skip to content

Commit 85c988d

Browse files
sebstofabianfett
andauthored
Update Sources/AWSLambdaRuntime/LambdaRuntime.swift
Co-authored-by: Fabian Fett <[email protected]>
1 parent 57e2396 commit 85c988d

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

Diff for: Sources/AWSLambdaRuntime/LambdaRuntime.swift

+6-17
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,14 @@ public final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: St
6161

6262
// if the original value was already true, run() is already running
6363
if original {
64-
throw LambdaRuntimeError(code: .runtimeCanOnlyBeStartedOnce)
64+
throw LambdaRuntimeError(code: .moreThanOneLambdaRuntimeInstance)
6565
}
66-
67-
try await withTaskCancellationHandler {
68-
// call the internal _run() method
69-
do {
70-
try await self._run()
71-
} catch {
72-
// when we catch an error, flip back the global variable to false
73-
_isRunning.store(false, ordering: .relaxed)
74-
throw error
75-
}
76-
} onCancel: {
77-
// when task is cancelled, flip back the global variable to false
78-
_isRunning.store(false, ordering: .relaxed)
66+
67+
defer {
68+
_isRunning.store(false, ordering: . releasing)
7969
}
80-
81-
// when we're done without error and without cancellation, flip back the global variable to false
82-
_isRunning.store(false, ordering: .relaxed)
70+
71+
try await self._run()
8372
}
8473

8574
private func _run() async throws {

0 commit comments

Comments
 (0)