与调度组.通知直到最后一刻才打来调度组请假是叫,所以你叫
enter
外部
leave
里面
比如:
func findPath(node: Node) {
if !node.isValid { return }
dispatchGroup.enter()
queue.async { //concurrent queue
findPath(node.north)
dispatchGroup.leave()
}
dispatchGroup.enter()
queue.async {
findPath(node.west)
dispatchGroup.leave()
}
dispatchGroup.enter()
queue.async {
findPath(node.south)
dispatchGroup.leave()
}
dispatchGroup.enter()
queue.async {
findPath(node.east)
dispatchGroup.leave()
}
}
func findPaths(startNode: Node) {
findPath(node: startNode)
dispatchGroup.notify {
print("All done")
}
}