Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions foundation/src/extensions/ArrayCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

millor posar el delay factor davant ja que sino no es pot fer els trailing clousures
també li treuria la paraula factor de la variable, amb delay ja s'enten no?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delayFactor perquè no és un delay, i ho he posat darrere el then perquè com que té un valor per defecte no haver-lo d'omplir ni modificar el codi de les apps 🤔

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
*/
Expand Down