I'm trying to understand what will be the correct way to create Serial Dispatch Group for background threaded tasks. Example:
I have a video which I want to split into 5 parts. So in theory this will be the queue cycle:
AVAssetExportSession
on a background threadAVAssetExportSession
on a background threadI've been digging through tutorials regarding this issue, yet I couldn't find an appropriate way to achieve this.
Any help would be highly appricated!
Best Regards, Roi
Synchronization via groups is useful if the tasks are to be processed in parallel and serially and the last task is unclear. But your problem is completely serial.
Why don't you use just a serial queue for your purpose? You can add the five blocks to that queue and they will be executed in the desired order. You might also solve your problem with just a single block running in background.
There's no such thing as a "serial dispatch group". Serial/concurrent is a property of a queue, not of a group.
Given that AVAssetExportSession
is, itself, an asynchronous process, simple attempts to add it to a serial queue will not work. Two approaches seem logical. You can either:
You can wrap the exportAsynchronously(completionHandler:)
in an asynchronous custom Operation
subclass. You can then add these five operations to a serial Operation queue. You can give them individual completion blocks if you want. And/or you can then make a completion operation dependent on those five operations.
or
You can write a recursive function that performs request i
, and in its completion handler, you can have it call itself for i + 1
. And it just needs to check to see if i < 5
(or whatever).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With