I want to let queue1 finish and use the data I get in CardTheme and use this data to call the second API. I want to use the group.wait() to achieve this. But it stuck at all. It seems that my group is in main thread and cause the deadlock. I use the Moya package to call my API. How to wait one API's response back and use data call another API?
let queue1 = DispatchQueue(label: "getBirthdayCardTheme", attributes: .concurrent)
let queue2 = DispatchQueue(label: "getBirthdayCardDetail", attributes: .concurrent)
let group = DispatchGroup()
group.enter()
queue1.async(group: group){
InsuranceDataModel.shared.getCardTheme(completionHandler: {
group.leave()
},errorHandler:{
group.leave()
})
}
group.wait()
group.enter()
queue2.async(group: group){
InsuranceDataModel.shared.getCardDetail(sender_theme_id: "", pageSize: "1", pageNow: "1", completionHandler: {
group.leave()
}, errorHandler: {
group.leave()
})
}
I edit my code and this works great for a workaround.This weird that group.wait() can't use and cause view freeze.
let group = DispatchGroup()
group.enter()
InsuranceDataModel.shared.getCardTheme(completionHandler: {
//get sender_theme_id here
group.leave()
},errorHandler:{
group.leave()
})
group.notify(.main){
InsuranceDataModel.shared.getCardDetail(sender_theme_id: "", pageSize: "1", pageNow: "1", completionHandler: {
}, errorHandler: {
})
}