Friday, September 30, 2022
HomeiOS Developmentios - Look ahead to closure completion to make a synchronous operate...

ios – Look ahead to closure completion to make a synchronous operate return


I’ve a operate that returns a Bool. This Bool worth is about inside a closure that’s executed after get community response(community request is carried out in a background thread).

The issue is that I want to attend for closure completion ir order to acquire the worth that I have to return.

So as to obtain this I’ve used DispatchGroup nevertheless it doesn’t work. As end result my utility is get blocked by some sort of impasse.

non-public func isOriginal() -> Bool {
        let group = DispatchGroup()
        var isOriginal = true
        group.enter()
        let parameters = GetIsOriginalParameters(completion: { end in
            defer {
                group.depart()
            }
            guard case .success(let isOriginalResult) = end result else {
                return
            }
            isOriginal = isOriginalResult
        })
        getIsOriginalUseCase.run(parameters) //calls community request 
        group.wait()
        return isOriginal
    }

Discover that I’ve take a look at with DispatchSemaphore acquiring similar behaviour.
I am unable to help Async/Await

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular