From d1913ea9ba12f512b0e5e54713a03ea091ec5968 Mon Sep 17 00:00:00 2001 From: Josh Wright Date: Fri, 1 Sep 2023 16:42:35 -0700 Subject: [PATCH] Fix NSRecursiveLock API --- .../Alchemy/Services/Container/Container.swift | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Sources/Alchemy/Services/Container/Container.swift b/Sources/Alchemy/Services/Container/Container.swift index 8eb966f5..5fc572b0 100644 --- a/Sources/Alchemy/Services/Container/Container.swift +++ b/Sources/Alchemy/Services/Container/Container.swift @@ -238,3 +238,20 @@ public final class Container: CustomDebugStringConvertible { """ } } + +#if os(Linux) +extension NSRecursiveLock { + fileprivate func withLock(_ body: () throws -> R) rethrows -> R { + self.lock() + let value: R + do { + value = try body() + } catch { + self.unlock() + throw error + } + self.unlock() + return value + } +} +#endif