如何在时间后停止 DispatchGroup? iOS

How to stop DispatchGroup after time? iOS

我正在使用 DispatchGroup,我用它来执行来自两个不同服务器的两个请求。当响应来自两个服务器时,DispatchGroup被调用notify(),问题是服务器的一个响应可能不会来(发生过一次)DispatchGroup如何在一段时间后通知自己?或者我怎样才能停止 DispatchGroup?我做了一个例子,但我认为这不是我需要的。

Timer.scheduledTimer(withTimeInterval: 7.5, repeats: false) { [weak self] (timer) in
        guard let _self = self else { return }
        DispatchQueue.main.async {
            if _self.leaveDispatchGroupDigit == 0 {
                _self.requestGroup.leave()
                _self.requestGroup.leave()
            }
            if _self.leaveDispatchGroupDigit == 1 {
                _self.requestGroup.leave()
            }
        }
    }

在这种情况下,为请求创建超时是最干净的解决方案:)