New background task modes

This commit is contained in:
Christoph Hagen
2021-01-13 21:43:46 +01:00
parent 746b69defc
commit ffbacb7645
13 changed files with 797 additions and 661 deletions

View File

@@ -0,0 +1,28 @@
//
// 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
}
}