DispatchQueues: Serial, Concurrent, Async, & Sync – Overview

preview_player
Показать описание
In this video we will dive into the differences of serial and concurrent dispatch queues. A pillar of iOS Development to schedule work, we'll also talk through sync and async work being executed with examples.

** Popular Series

** Get Skillshare free for 2 Months and learn iOS

** Manage all your investments from app earnings on Betterment!

** Grow your own Youtube tech channel with TubeBuddy:

#swift #concurrency #iOSDeveloper
Рекомендации по теме
Комментарии
Автор

You did not explain sync vs async really well.
The main difference between those is:
Sync: Blocks the caller queue until the task is done (serial or concurrent.
Async: Does not block the caller queue.

Serial queue: Executes tasks one after the other in just one thread
Concurrent queue: Executes tasks in parallel in a different queue's thread

On your first example, the main reason why it printed "1" it's because you can never call sync{} from the same queue AND to the same queue (serial or concurrent). You'll end up with a deadlock and a crash most of the time.

hibviow
Автор

This channel is a gold mine for those who want to develop and sharpen their iOS development skills! Thanks man!

Karan-jreo
Автор

Great content man, keep up the good work & ty for your effort

muromuro
Автор

Awesome, I have been waiting for this

duongthang
Автор

Great one, do more videos related to concurrent and thread concepts

jayaseelankumarasamy
Автор

Oh, my god...
I always hard to understand this.
thx so much 😭
actually many answer replied on your community and I am one of them LOL

martinq
Автор

thank you! could you make a video to explain the iOS app lifecycle?!! Thank you again! love this channel so much!

laurapotter
Автор

Hi Afraz, please put all 2021 swift tutorials in one playlist

dasturchi
Автор

I still don’t understand why only “1” printed at the beginning…

proxa
Автор

I tried before with a certain api to make a request serially by write a code as you did but it did not work.
Does "task.resume()" or "session" have an effect on that?

jtuurus
Автор

So to understand it, when we are calling sync, we are telling the queue to make itself available, free from any ongoing tasks (sync or async) or just complete the current task and make itself available.
But as the sync block was called inside the async block, although the queue can put the async operation on hold and take other tasks, but cannot make itself completely available for the sync block to run. The sync block is demanding the full availability of the queue, but the ongoing async block cannot complete unless that sync block completes.

Can someone please confirm it?

sharungarg
Автор

More content with Reactive Programming with RxSwift and also about Clean Architecture.

rev_kous
Автор

queue.sync refers to that particular queue doesn't it? instead if you specifically point to queue.main.sync would be the same than not using the queue itself since you're poining right to the main thread am i right?

hoy
Автор

i get it why 1 is printed in the first block of code i.e 

queue.async { 
print("1")
queue.sync {
print("2")
queue.sync{
print("3")
}
}
}


but why the last two async blocks containing "4" and "5" are not executed despite them being called out of the first scope ? i tried to think about it and thought because the queue will be busy performing print("1") but it supposed to be serial so once its finished the first block it will move to execute the next two blocks i believe there is something i am misunderstanding here its confusing little bit, would appreciate some help

jameelshehadeh
Автор

Hey 👋 You forgot to talk about concurrency problems such as race conditions, deadlock etc

protodimbo
Автор

But still it's not clear to me why it printed "1" and not 1, 4, 5

sumeetbhujang
Автор

Sorry but you didn't explain many things. Why did the 1 print? The difference between sync and async is not clear from your explanation or example.

csmaca
Автор

I respect your intention to try to explain things, but your explanation of sync/async is just bad and might only confuse fresh iOS devs

oleksandrbalan