mirror of
https://github.com/xtool-org/xtool.git
synced 2026-11-16 20:41:53 +03:00
22 lines
443 B
Swift
22 lines
443 B
Swift
import Foundation
|
|
import Supersign
|
|
|
|
func withSyncContinuation<T>(
|
|
_ action: (_ cont: @escaping (T) -> Void) -> Void
|
|
) -> T {
|
|
var value: T!
|
|
let sem = DispatchSemaphore(value: 0)
|
|
action {
|
|
value = $0
|
|
sem.signal()
|
|
}
|
|
sem.wait()
|
|
return value
|
|
}
|
|
|
|
func withSyncContinuation<T>(
|
|
_ action: (_ cont: @escaping (Result<T, Error>) -> Void) -> Void
|
|
) throws -> T {
|
|
try withSyncContinuation(action).get()
|
|
}
|