mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-08 22:33:26 +01:00
38 lines
764 B
Swift
38 lines
764 B
Swift
//
|
|
// NSManagedObjectContext+Conveniences.swift
|
|
// AltStore
|
|
//
|
|
// Created by Riley Testut on 5/16/23.
|
|
// Copyright © 2023 Riley Testut. All rights reserved.
|
|
//
|
|
|
|
import CoreData
|
|
|
|
public extension NSManagedObjectContext
|
|
{
|
|
// Non-throwing
|
|
func performAndWait<T>(_ closure: @escaping () -> T) -> T
|
|
{
|
|
var result: T!
|
|
|
|
self.performAndWait {
|
|
result = closure()
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
// Throwing
|
|
func performAndWait<T>(_ closure: @escaping () throws -> T) throws -> T
|
|
{
|
|
var result: Result<T, Error>!
|
|
|
|
self.performAndWait {
|
|
result = Result { try closure() }
|
|
}
|
|
|
|
let value = try result.get()
|
|
return value
|
|
}
|
|
}
|