DispatchGroup: check how many “entered”

倖福魔咒の 提交于 2019-12-23 10:17:41

问题


I'm using Swift 3 DispatchGroup to wait until multiple async operations are finished (according to this answer which works perfect and as expected.

Is there a way to check how many operations are entered already, like dispatchGroup.count or something like that?


回答1:


NO, nothing. You need to balance your enter() and leave() by yourself without counting.

DispatchGroup




回答2:


You can see counts of enters to the group in debug description:

OS_dispatch_group: group[0x60000221d950] = { xref = 3, ref = 3, count = 2, gen = 0, waiters = 0, notifs = 1 }

and extract int value out of it:

let count = dispatchGroup.debugDescription.components(separatedBy: ",").filter({$0.contains("count")}).first?.components(separatedBy: CharacterSet.decimalDigits.inverted).compactMap{Int($0)}.first


来源:https://stackoverflow.com/questions/45610271/dispatchgroup-check-how-many-entered

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!