Caps-iOS/CapCollector/Extensions/DispatchGroup+Extensions.swift
2021-01-13 21:43:46 +01:00

29 lines
677 B
Swift

//
// DispatchGroup+Extensions.swift
// CapCollector
//
// Created by iMac on 13.01.21.
// Copyright © 2021 CH. All rights reserved.
//
import Foundation
extension DispatchGroup {
typealias AsyncSuccessCallback = (Bool) -> Void
static func singleTask(timeout: TimeInterval = 30, _ block: (@escaping AsyncSuccessCallback) -> Void) -> Bool {
let group = DispatchGroup()
group.enter()
var result = true
block { success in
result = success
group.leave()
}
guard group.wait(timeout: .now() + timeout) == .success else {
return false
}
return result
}
}