GCD II
Async vs Sync.
GCD II
Async vs Sync.
0
0
Checkbox to mark video as read
Mark as read

Async vs Sync

All the queues we've seen so far have been executed with the keyword async. However, there's an option to execute them with sync. The difference is that async tasks will not run until sync tasks have finished their execution.

Let's see an example using two queues with async.

DispatchQueue.global(qos: .background).async {
    for i in 0..<5 {
        print("👾 \(i)")
    }
}

DispatchQueue.global(qos: .userInteractive).async {
    for i in 0..<5 {
        print("🤖 \(i)")
    }
}

As we mentioned earlier, .userInteractive has higher priority than .background.

🤖 0
👾 0
👾 1
🤖 1
🤖 2
🤖 3
🤖 4
👾 2
👾 3
👾 4

If we execute our background queue with sync, we will see that this queue finishes execution first.

Continue reading

Access to all the content with our plans.

Basic Plan

FREE

Start Now
  • Junior level content
  • Senior level content
  • Expert level content
  • Extra content
  • Question submissions
Monthly
Yearly

Plan logo

-

Unlimited access to the whole content

  • Junior level content
  • Senior level content
  • Expert level content
  • Extra content
  • Question submissions

Stripe secure payment methods
Plan logo

-

Unlimited access to the whole content

  • Junior level content
  • Senior level content
  • Expert level content
  • Extra content
  • Question submissions

Stripe secure payment methods
Plan logo

-

Solve your doubts at any level

  • Junior level content
  • Senior level content
  • Expert level content
  • Extra content
  • 2 Question submissions per week

Stripe secure payment methods
Plan logo

-

Solve your doubts at any level

  • Junior level content
  • Senior level content
  • Expert level content
  • Extra content
  • 2 Question submissions per week

Stripe secure payment methods

0 Comments

Join the community to comment
Sign Up
I have an account
Be the first to comment

Accept Cookies

We use cookies to collect and analyze information on site performance and usage, in order to provide you with better service.

Check our Privacy Policy