DispatchGroup: check how many “entered”

后端 未结 2 695
刺人心
刺人心 2020-12-17 18:02

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

相关标签:
2条回答
  • 2020-12-17 18:40

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

    DispatchGroup

    0 讨论(0)
  • 2020-12-17 18:42

    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
    
    0 讨论(0)
提交回复
热议问题