// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers // // SPDX-License-Identifier: MPL-2.0 import Foundation public actor AsyncThunk { private var storage: Value? private var thunk: (() async -> Value)? public init(thunk: @escaping @Sendable () async -> Value) { self.thunk = thunk } public init(value: Value) { self.storage = value } public func value() async -> Value { if let storage { return storage } if let thunk { let computed = await thunk() self.storage = computed self.thunk = nil return computed } fatalError("AsyncThunk has neither thunk nor storage.") } }