change name to hiddifypackettunnel

This commit is contained in:
Hiddify
2024-09-03 22:52:04 +02:00
parent a644b7fe5c
commit d388c1995e
13 changed files with 39 additions and 56 deletions

View File

@@ -0,0 +1,43 @@
//
// Extension+RunBlocking.swift
// SingBoxPacketTunnel
//
// Created by GFWFighter on 7/25/1402 AP.
//
import Foundation
import Libcore
import NetworkExtension
func runBlocking<T>(_ block: @escaping () async -> T) -> T {
let semaphore = DispatchSemaphore(value: 0)
let box = resultBox<T>()
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 tBlock()
box.result = .success(value)
} catch {
box.result = .failure(error)
}
semaphore.signal()
}
semaphore.wait()
return try box.result.get()
}
private class resultBox<T> {
var result: Result<T, Error>!
var result0: T!
}