I am currently working on a swift animation. This animation gets triggered by an another function in unsteady time intervals (connected to a server). The animation takes 2 seconds to finish but its possible that it gets triggered before it has finished. Thats why I was thinking about creating a waiting queue which stores the triggering events until the animation is completed and can be restarted. So on the one hand side I have to lock the animation function until its ready again and one the other I need some kind of storage for the incoming events in the meantime. I was already thinking about dispatch groups but couldnt figure out how I could use them. I would be really happy about any input in which direction I could go to solve this problem.
Triggering function:
private func subscribeToNewBLock() {
DispatchQueue.global(qos:.userInteractive).async {
watchForNewBlock() {result in
switch result {
case .Failure:
return
case .Success(let result):
//Animation function
self.moveBlocksDown(blockNumber: result)
//Recursive call to keep listening for new blocks
self.subscribeToNewBLock()
}
}
}
}
You may try to make your animation queue as like below example