From 08220ef3cdb025c87b879f56f79d3a70edde466d Mon Sep 17 00:00:00 2001 From: Pau Benet Prat Date: Wed, 10 May 2023 13:54:23 +0200 Subject: [PATCH] Added run after with default delayFactor of 100. --- foundation/src/extensions/ArrayCollection.swift | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/foundation/src/extensions/ArrayCollection.swift b/foundation/src/extensions/ArrayCollection.swift index 80e910b..f8d8354 100644 --- a/foundation/src/extensions/ArrayCollection.swift +++ b/foundation/src/extensions/ArrayCollection.swift @@ -220,17 +220,19 @@ extension Array { * Runs the block for all elements and when they all finishes the allFinished is called. * To know the block is finished the then() must be called in the async block */ - public func eachAsync(_ body:(_ element:Element, _ index:Int, _ then:@escaping()->Void) -> Void, allFinished:@escaping(()->Void)){ + public func eachAsync(_ body:(_ element:Element, _ index:Int, _ then:@escaping()->Void) -> Void, allFinished:@escaping(()->Void), delayFactor:Float=100){ let group = DispatchGroup() for (index, element) in self.enumerated() { group.enter() - body(element, index) { - group.leave() + run_after(Double(index/delayFactor)) { + body(element, index) { + group.leave() + } } } group.notify(queue: .main) { allFinished() } } - + /** * Same as map but providing the index of the element in the array */