Refactor task usage and profile auto update

This commit is contained in:
世界
2023-09-22 11:32:51 +08:00
parent 390e063f20
commit 3374f8e727
49 changed files with 823 additions and 636 deletions
+16 -3
View File
@@ -2,12 +2,24 @@ import Foundation
import Libbox
import NetworkExtension
func runBlocking<T>(_ body: @escaping () async throws -> T) throws -> T {
func runBlocking<T>(_ block: @escaping () async -> T) -> T {
let semaphore = DispatchSemaphore(value: 0)
let box = resultBox<T>()
Task {
Task.detached {
let value = await block()
box.result0 = value
semaphore.signal()
}
semaphore.wait()
return box.result0
}
func runBlocking<T>(_ tBlock: @escaping () async throws -> T) throws -> T {
let semaphore = DispatchSemaphore(value: 0)
let box = resultBox<T>()
Task.detached {
do {
let value = try await body()
let value = try await tBlock()
box.result = .success(value)
} catch {
box.result = .failure(error)
@@ -20,4 +32,5 @@ func runBlocking<T>(_ body: @escaping () async throws -> T) throws -> T {
private class resultBox<T> {
var result: Result<T, Error>!
var result0: T!
}