how are the tasks run under print(“=== Group of sync tasks ===\n”) this statement synchronous?
We are using workerQueue’s(which is a concurrent queue) async call to call slowAdd((Int, Int))
running your code, the Animations completed message appears too soon, because the animate tasks appear to finish immediately (you dispatched them asynchronously, so they return immediately).
To make the group wait for the task to really finish, you need to specify when the task enters and leaves the group: enter before the animations, and leave in the completion handler. The code below works the same as the finished challenge playground:
Thanks so much for you applying. Really, I misunderstood the async(group:) function. Its duty is just dispatching block specific groups, but not include when the block is executed. That’s why we need group.enter/leave to control the exact time, right?
The purpose of GCD and OperationQueue is to make synchronous tasks behave asynchronously. But there are features we want to use with APIs that are already asynchronous, so we need a way to tell the system when they really finish.