I have a following code structure, how can I run this code on background thread and execute all the methods serially in FIFO.
How to wait for function to executes all its statements and then move to next function?
func downloadImagesAndProcess(){
// i need these methods to execute one by one i.e when saveimages completes fully only then call resizeimages
saveImages()
resizeImages()
shareImgs()
}
func saveImages(){
// long async tasks
for (index, image) in (self.images.enumerated())! {
KingfisherManager.shared.retrieveImage(with: URL(string:image.imageFile)!) { result in
switch result {
case .success(let value):
self.saveImageDocumentDirectory(image: value.image, imageName: imgNameStr)
case .failure(let error):
print(error) // The error happens
}
}
}
}
func resizeImages(){
// long running tasks
}
func shareimgs(){
//share
}
I need these methods to execute one by one i.e. when saveImages
completes fully only then call resizeImages
How to wait for function to executes all its statements and then move to next function?