0

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
         }
     }

}

Jay
  • 35
  • 1
  • 7
  • 3
    There is no inherent reason it would cause any problems. It simply delays the execution of the code by one extra iteration of the RunLoop. There could be bugs in the code not shown, but that is, well, not shown – Paulw11 Aug 24 '21 at 06:07
  • 3
    It won't cause a bug but adding a second (redundant) async block is pretty amateurish. – vadian Aug 24 '21 at 06:30

0 Answers0