I have a task to call functions with a certain order synchronously with respect to each other.
I realized my function, but for some reason when I checked it, I found an anomaly. Let's say if you make a list of calls to resolve which rights and when you stop to resolve the first request for about 1 minute, the other permissions will slip through
class RunFuncs {
typealias TypeFuncCall<T> = ((_ completed: @escaping (T) -> Void) -> Void)
static func cascad<T>(dispatchQueue queue: DispatchQueue,
callFuncs funcs: [TypeFuncCall<T>],
indexFuncRun index: Int = 0,
completedAll: @escaping (([T]) -> Void)) {
queue.async {
guard (funcs.count > index) else {
completedAll([T]())
return
}
let callOne = funcs[index]
let indexNext = (index + 1)
callOne() { [completedAll, funcs, indexNext] (resultOne) in
RunFuncs.cascad(dispatchQueue: queue,
callFuncs: funcs,
indexFuncRun: indexNext,
completedAll: { (resultOther) in
var resultAll = resultOther
resultAll.insert(resultOne, at: 0)
completedAll(resultAll)
})
}
}
}
}