Swift Dispatch Group Question Threading Questions

549 Views Asked by At

Will there be any potential bug if the code written like this? Basically the dispatch group's notify closure is already on main thread but my tech lead added DispatchQueue on main again inside the notify closure. I tried to push on removing DispatchingQueue.main.async {} call but their response was it's already been QA-ed and told me not to touch it, afraid that I might cause a bug.

Will there be any threading issue?

func foo(completion: @escaping () -> Void) {
     let group = DispatchGroup()
     
     group.enter()
     self.fetchData1() {
         // code
         group.leave()
     }

     group.enter()
     self.fetchData2() {
         // code
         group.leave()
     }

     group.notify(queue: .main) {
         DispatchQueue.main.async {
          // code
          return completion() //yeah... idk why it's written like this
         }
     }

}

0

There are 0 best solutions below