Questions tagged [dispatchgroup]

A group of tasks that you monitor as a single unit in Swift language by Apple.

47 questions
3
votes
1 answer

Does DispatchGroup wait forever?

I am wondering about the following scenario. I have a DispatchGroup inside a function. Now I am entering the group on a background thread and calling wait(). func test() { let group = DispatchGroup() DispatchQueue.global().async { …
3
votes
1 answer

Swift - Why is DispatchGroup not working in this function?

I am waiting for idToken response before returning the variable. Please don't tell me to just use completion handler and call it without a DispatchGroup. I know I can do that, but I am trying to understand why this logic does not work. func…
Sam KC
  • 61
  • 1
  • 8
2
votes
1 answer

Why can Objective-C dispatch_group_create() return NULL but not Swift DispatchGroup()?

I noticed a disparity between the Swift API for dispatch groups and the Objective-C API. The init() for DispatchGroup() returns a non optional value. But the Objective-C dispatch_group_create() mentions a possibility for a NULL return: Return…
user16217248
  • 3,119
  • 19
  • 19
  • 37
2
votes
1 answer

DispatchQueue freezed main queue

I need to do some methods one by one without interrupting, in a separate thread, that way I have in my class fileprivate var queue = DispatchQueue(label: "ProgressHUD", qos: .userInteractive) and when I need show/hide I do some like this queue.sync…
EvGeniy Ilyin
  • 1,817
  • 1
  • 21
  • 38
2
votes
1 answer

Swift - Run 1000 async tasks with a sleeper after every 50 - how to communicate btw DispatchGroups

I have to run 1000 async calculations. Since the API has a limit of 50 requests/min I have to split it up into chunks of 50 and wait for a minute after processing once chunk. Eventually I want to print the results. resultsArray = [Double]() //…
phoebus
  • 1,280
  • 1
  • 16
  • 36
2
votes
1 answer

How can you use Dispatch Groups to wait to call multiple functions that depend on different data?

I have three variables, a, b and c. I have three asynchronous functions with completion blocks to update these variables and three more functions that do some work with only some of the data. I'm making sure that the working functions wait until all…
Josh Paradroid
  • 1,172
  • 18
  • 45
1
vote
1 answer

DispatchGroup to wait for Firestore query completion

I am running multiple Firestore queries in a single user tapGesture, which requires me to ensure that there are minimum to no simultaneous Firestore queries running in the app. I have read multiple answers(Waiting until the task finishes) on this…
1
vote
0 answers

How to stop DispatchGroup manually (When we reach a certain value) and get it to call .notify (finish all executions manually)

This is different than wanting to stop after a period of time. An example of possible use case: func calculate(_ nums: [Int], _ target: Int, completion: @escaping (([Int]) -> Void)) { let enumerated = nums.enumerated() let queue =…
1
vote
0 answers

How can I abort the entire dispatch group operation upon a single failure without returning multiple failure completion handlers?

I use dispatch group in a loop in order to keep track an array of network requests so when they are all successfully completed then the successful completion handler is returned only once. However, if a single failure occur, I want to abort the…
user10711707
  • 135
  • 1
  • 7
1
vote
2 answers

Swift -is it necessary to call continue when leaving a dispatchGroup

I have a group of objects that I have to iterate through using a for-loop and DispatchGroup. When leaving the group inside the for-loop, is calling continue necessary? let group = DispatchGroup() for object in objects { group.enter() if…
Lance Samaria
  • 17,576
  • 18
  • 108
  • 256
1
vote
3 answers

How to make for-in loop wait for data fetch function to complete

I am trying to fetch bunch of data with for in loop function, but it doesn't return data in correct orders. It looks like some data take longer to fetch and so they are mixed up in an array where I need to have all the data in correct order. So, I…
1
vote
1 answer

How to make a common resource thread safe when using dispatch group?

I have a class User which needs to be updated every time a user opens the app class User : NSObject, NSCoding { var vehicles : [Vehicles] var bankaccounts : [BankAccounts] var friends : [Friends] } In my home screen ViewController, I…
1
vote
1 answer

Benefit of using DispatchGroup over a basic counter class

I have a situation where I need to wait for a group of tasks to complete before executing some UI rendering code. Some of these tasks are network requests which will always complete and leave the dispatch group. Some however, are not network…
Nick
  • 150
  • 1
  • 12
0
votes
1 answer

Multiple threads calling same function Swift/SwiftUI

I have scenario where threads calling the same method which is having timer, for each thread timer will be different because thread created in different timeline based on the action from the UI. How can I get the timer value for each thread…
OhStack
  • 106
  • 1
  • 1
  • 15
0
votes
2 answers

In Swift, how do you loop through a list and hand one item at a time to a function with completion closure?

I'm trying to process a folder with audio files through speech to text recognition on MacOS. If I just process one file, it works, but if I feed multiple files, only one file works and throws an error for rest. I thought I could use DispatchGroup,…
jl303
  • 1,461
  • 15
  • 27
1
2 3 4