Dependencies with Operation queue & Dispatch Serial queue Swift Hindi Tutorial

Поділитися
Вставка
  • Опубліковано 2 сер 2024
  • Operation queue and Dispatch framework (GCD) in swift are two ways of handling concurrent operations in Swift, but when it comes to dependencies then in that case Operation queue has always been the preferred choice for iOS developers.
    But what gives operation queue the edge in the case of handling these dependencies and why should we use them? How are they different from GCD serial queues? You will find all the comparisons done in this video which will help you to make the right decision while coming into situations where you need to handle dependencies in your iOS project.
    Given are the chapters covered in the video
    0:00 introduction
    0:42 codecat15 example
    1:22 dependency scenario
    2:31 dependencies using operation queue
    6:17 dependencies using GCD serial queue
    8:06 operation queue vs GCD serial queue
    9:28 my opinion
    10:55 next session
    11:11 conclusion
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ✅ Subscribe to the channel and stay ahead of everyone by following the right way for writing clean code in swift. 🔥🔥🔥🔥🔥
    🔗Click on the link to subscribe: ua-cam.com/users/codecat?sub...
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    -----------------------------------------------------------------------------------------------------------------------
    📥 Download the source code from
    Github: github.com/codecat15/UA-cam-...
    Google Drive: drive.google.com/file/d/1NHgV...
    -----------------------------------------------------------------------------------------------------------------------
    ############################################
    Connect with me on social media
    📧: codecat15@gmail.com
    🐦: / codecat15
    Facebook: / code.cat.792
    Github: github.com/codecat15
    ###########################################
    #dependenciesInSwift #OperationQueue #DispatchQueue

КОМЕНТАРІ • 62

  • @rishabhsrivastava9849
    @rishabhsrivastava9849 3 роки тому +14

    I have cracked 3 interviews so far and your videos are big help!!!

    • @CodeCat15
      @CodeCat15  3 роки тому +4

      Congratulations Rishabh on clearing off the interviews I am glad to be a part of your success journey.

  • @hardikpatel9856
    @hardikpatel9856 Рік тому +1

    I'm watching the second time 😂 code cat ji... Super useful 👍😄

    • @CodeCat15
      @CodeCat15  Рік тому +1

      Glad it was helpful Hardik 👍

  • @madmaxcoder6209
    @madmaxcoder6209 3 роки тому

    Even if you pay to any private coaching or any online training platform they will never cover such topics in details and here we have ravi who simply shares it with the community. Thank you for sharing your knowledge and helping us grow and be better.

  • @rahulrathod8552
    @rahulrathod8552 2 роки тому +1

    Hi, when i was fresher i used see lot of videos for swift, but they just help you to solve the problem, but in your videos we'll get complete package of any topic, that exactly we want while working in IT industries. I really feel RESPECT ❤for you. you are the real Teacher. Thank you so much RAVI 🙏

    • @CodeCat15
      @CodeCat15  2 роки тому +1

      Hey Rahul, Thank you for your kind words it means a lot 😊

  • @MandeepSingh-ly3jj
    @MandeepSingh-ly3jj 3 роки тому +1

    Huge Respect for Ravi Sir, He is genius Guy, With the help of him videos related to an iOS , I was selected in reputed company , and now I have around 2year of experience and salary package is also great . all credit to Ravi sir. Salute to this man bcz I was selected in covid time and also I supported to my family with my earning. Again Really thanks from my heart. :)))

    • @CodeCat15
      @CodeCat15  2 роки тому

      It was all your hard work Mandeep and I am happy that I played a part in your success journey. All the best

  • @deepakkumar-qz1ud
    @deepakkumar-qz1ud 2 роки тому

    Your way of explanation and examples are Amazing bro....

  • @rushabhsingh2148
    @rushabhsingh2148 3 роки тому +2

    Thank you so much for the quality content you are providing. Really inspiring. Watching all your old videos

    • @CodeCat15
      @CodeCat15  3 роки тому +1

      Thanks Rushabh I am glad these videos are helpful plz feel free to ask questions and do share the channel with your iOS group

  • @harshsharma-hc4dx
    @harshsharma-hc4dx 3 роки тому +1

    All your videos are very informative and easy to understand with practical implementation.

  • @mohammadahmed9838
    @mohammadahmed9838 2 роки тому

    Thanks for the best tutorials! It really helped me out.

  • @karthikeyaacharya8424
    @karthikeyaacharya8424 3 роки тому +1

    Simple, elegant and very helpful videos. Thanks for all your effort.

    • @CodeCat15
      @CodeCat15  3 роки тому

      Glad you like them and welcome to the channel Karthikeya

  • @dhavalnena7386
    @dhavalnena7386 2 роки тому +1

    Very well explained. Thank you!

  • @khadijadaruwala3380
    @khadijadaruwala3380 3 роки тому +2

    Thank you for your videos, they are informative. Would request/suggest you create a video on Managing Different Environment (development, staging, production, etc) and app release process in iOS Swift as I am currently struggling with this and a good detailed video on this topic would be really helpful.

    • @CodeCat15
      @CodeCat15  3 роки тому +1

      This is a good suggestion Khadija, I have a way of managing multiple environment in my code and will surely share it with the community soon.

  • @sagarchandradas6326
    @sagarchandradas6326 2 місяці тому +1

    Gold Content

    • @CodeCat15
      @CodeCat15  Місяць тому

      Thank you Sagar, please feel free to ask more questions and do share the channel with your iOS group.

  • @arunkumariosp
    @arunkumariosp 3 роки тому +1

    one detail video for weak and strong in storyboard outlets and classes as well in closures and any other option is available. By the way great content , keep it up.

    • @CodeCat15
      @CodeCat15  3 роки тому +1

      In the ARC video I have explained weak so do check it out hope that should be okay if not then do let me know I will be happy to make a video on this.

  • @sarikapaghdal6150
    @sarikapaghdal6150 2 роки тому +1

    Hi ravi, I am very confused here. We have serialQueue, 3 blocks and you used serialQueue.async{} so its a sequential output! if we use serialQueue.sync{} what does that mean then? sync and async on queue are very confusing! suppose we have 3 separate queues , one for each of this block of task instead of one queue here we use async on them then output is not sequential. why is that happening? or I didn't get this sync and async concept.

  • @kishansuthar3037
    @kishansuthar3037 3 роки тому +2

    Upload video on Combine framework.

    • @CodeCat15
      @CodeCat15  3 роки тому

      after threading series, combine will be next in line

  • @abhijitkotangale170
    @abhijitkotangale170 3 роки тому +1

    👍 verynice

  • @akanksha2143
    @akanksha2143 3 роки тому +1

    This video is great. Please make the use of semaphore for handling such dependencies, I used semaphore but that totally blocked the thread. Thanks a lot for your videos.

    • @CodeCat15
      @CodeCat15  3 роки тому +1

      Sure Akansha, I am slowly moving in that direction. Please feel free to ask more questions and do share the video with your iOS group

  • @mazedar_tv
    @mazedar_tv 2 роки тому

    plz also explain the usage of .completionBlock

  • @book6202
    @book6202 Рік тому

    What if syncOfflineEmployee() and syncOfflineDepartment() are async in nature like inside those methods we will hit api which will be async calls?
    In that case will serial queue perform task in same manner?

  • @Rahul-jf5kf
    @Rahul-jf5kf 2 роки тому

    when to use multiple addExecutionBlocks and when multiple blockOperations?

  • @parveshchauhan811
    @parveshchauhan811 2 роки тому

    Could you please explain what is the difference between sync and async keyword that we could see in our codes most of the times especially in Dispatch Queue? Can you explain it in new video? Thanks so much.

  • @cios3917
    @cios3917 3 роки тому +2

    Very nice information on this particular topic. Could you please explain what is the difference between sync and async keyword that we could see in our codes most of the times especially in Dispatch Queue? And What is Main and Global Queues? How it is being utilized?

    • @CodeCat15
      @CodeCat15  3 роки тому +1

      I have explained the same in the introduction to threading video. Please check it out using the below link and feel free to ask questions regarding the same
      Introduction to threading: ua-cam.com/video/OKfv_0FvEf0/v-deo.html

    • @fazlinnouzil3946
      @fazlinnouzil3946 3 роки тому

      But I have already watched that video before. But I couldn’t find anything like sync or async or global queue in that explanation. So curiously asking what does it mean and could you explain it.

    • @CodeCat15
      @CodeCat15  3 роки тому +1

      I see what you mean, I have touched those portion in the video maybe 2% but not fully so since I am focusing on threading as of now I will be covering most of it very soon :)

    • @fazlinnouzil3946
      @fazlinnouzil3946 3 роки тому +1

      @@CodeCat15 Thanks yaar!

  • @srikanthgali9615
    @srikanthgali9615 3 роки тому +1

    Hai Ravi,
    When we use sync in serial or concurent ... why main thread is blocking.

    • @CodeCat15
      @CodeCat15  3 роки тому +1

      Short answer: The main thread is reserved for user operations like touch, tap, scroll, etc and hence we should not be doing any heavy operations on it like API calling or any report generation, etc. For a detailed explanation, I request you to watch two of my videos for that, given are the link for the same
      Introduction to threading:ua-cam.com/video/OKfv_0FvEf0/v-deo.html
      Lazy loading: ua-cam.com/video/Bytv3PJjNi4/v-deo.html
      Hope it helps and if you still have questions feel free to drop them as comment

  • @Rahul-jf5kf
    @Rahul-jf5kf 2 роки тому +1

    Hi Ravi, Can you explain ?
    serialQueue with async call,
    serialQueue with sync call,
    and concurrentQueue with sync call,
    will all three give same result?

    • @CodeCat15
      @CodeCat15  2 роки тому

      What do you think will happen? Will they give the same result or will it be different in case of sync vs async
      First let’s understand what sync and async are, as they are two different concepts and behave differently
      I made a video on this concept long back, sharing the video link here, if you have already seen it then perhaps you can explain what will be the output of your above question and then we will discuss it from there 😊
      ua-cam.com/video/OKfv_0FvEf0/v-deo.html

  • @fitdevelopertv5148
    @fitdevelopertv5148 3 роки тому

    In serial queues, is Async and sync both provide the same result?

  • @nagarajvrao7249
    @nagarajvrao7249 3 роки тому +1

    Would be helpful if you include combine framework.

    • @CodeCat15
      @CodeCat15  3 роки тому +1

      After the threading series the channel will be focused on combine related topics in details

  • @poorankumar4208
    @poorankumar4208 Рік тому

    Very well explained but i have doubt
    7:12 you have used async why?

    • @SaimIrfan-zn5ru
      @SaimIrfan-zn5ru 5 місяців тому

      There is a difference in serial and async. Async means that the rest of the code will continue to run while serial means that the tasks given to the queue will be ran serially (One by One / First in first out order.). If someone wants to clear their concept regarding what I am talking about then watch this video: ua-cam.com/video/X9H2M7xMi9E/v-deo.html.

  • @rajanmaheshwari
    @rajanmaheshwari 3 роки тому +1

    Did you try this with actual APIs in your block operations? It won't work like showed the code in your video using sleep because when you'll process the API code, it will spawn a BG thread and will treat your block operation as completed. Ultimately starting the other operation until and unless you use something like Semaphores etc.
    All the API calls are asynchronous in nature, so even if you use a serialized queue, as soon as you make a web service call, the thread makes an async call and moves to make a second web service call.
    Or if there is a way with using the same piece of code and calling APIs serially, let us know.
    All I think it can be done either using Semaphores or Nested Closures or may be subclassing Operation class which I haven't tested yet.

    • @CodeCat15
      @CodeCat15  3 роки тому

      The sleep in the code was used as an example to mock a time-consuming task and with operation queue if you want to move a task to the background then you may set the quality of service of the operation queue to background
      operationQueue.qualityOfService = .background
      I am not very sure if you can set the same for a serial queue, have not tried doing that myself but if there is then would love to know about it.
      since APIs have their own nature as you have explained that's exactly the reason why I didn't want to show everything in one video and wanted to take it one functionality at a time.
      You can try using the 3 options you have mentioned but then since we have multiple options I would compare which is more suitable tool depending on the nature of my task.
      I tend to avoid using nested closure as much as I can because they lack code readability and things can get really ugly with them if you have too many operations but then that's just my preference because I can do the same thing using operation queue dependencies in a much cleaner and readable fashion.

    • @rajanmaheshwari
      @rajanmaheshwari 3 роки тому +1

      ​@@CodeCat15 I already got your sleep mock thing. I don't know what you mean to say " if you want to move a task to the background then you may set the quality of service of the operation queue to background". Whenever you perform a task using GCD or OQ while using async (without blocking UI), you spawn a bg thread. So, it is already in the background. QoS only helps the system to prioritize your tasks.
      Your operations were synchronous here that's why it worked.
      You can set a QoS in a serial queue. Not a problem
      Nested Closure is obviously a NO NO.
      I have always used Semaphores as they also solve the race conditions for the shared resources.
      I am looking forward to the operation queue code which performs APIs in a serial fashion using the dependency mechanism. I don't think we can achieve this without subclassing Operation or using any other mechanisms like Semaphores.

    • @CodeCat15
      @CodeCat15  3 роки тому

      Ohh I see perhaps I got the question wrong my bad I will surely try to cover these points in the API video thanks a lot for all these valuable points
      one more thing I would like to add here is if your operations are synchronous then I doubt there would be a race condition because only when a single operation is completed and the resource is released the next operation will trigger up but then race conditions are tricky and a lot depends on what we want to achieve depending on the requirement.

    • @rajanmaheshwari
      @rajanmaheshwari 3 роки тому +1

      ​@@CodeCat15 I think you again misunderstood with race condition part. The race conditions are only meant for async operations using a shared resource and using something like DispatchGroup since from the beginning my focus was only on Async ops. To avoid those, I use Semaphores or we can have our main element wrapped with a class using Dispatch Barriers in that.
      Sync is pretty simple and you can use anything with sync ops. (GCD/ OQ). And of course, there is no need to use Semaphores when we are performing sync operations.
      The main trick comes when you use async ops. They fail using the dependency or serial queue trick because the asynchronous nature makes the thread / Operation believe it's done and it jumps to another.
      I hope this time I was able to make you understand what I really intend to.

    • @CodeCat15
      @CodeCat15  3 роки тому

      @Rajan Maheshwari First of all thank you for being so patient with me and explaining your use case really appreciate the details that you have provided
      After your comment I made a small playground code using the same code shown in the video with API calls.
      given is the gist link: gist.github.com/codecat15/0ac54e150159f7c8a9c4b2d2b541781c#file-operationqueue_withapi-swift
      If you run the code you will observe:
      1. it does make the call in FIFO order
      2. as mentioned in the dispatch group video about URLSession running in their own separate thread (you too mentioned in the above comments) the impression here in the console is first API call logs are printed first and followed by the second API call logs.
      the above behavior is okay for some use cases in APIs but not all so will show them later in the dependency API video :)
      Coming to async operations with shared resources
      In the concurrency documentation by apple, they do mention that "A serial queue executes only one task at a time and always pulls tasks from the head of the queue. You might use a serial queue instead of a lock to protect a shared resource or mutable data structure. Unlike a lock, a serial queue ensures that tasks are executed in a predictable order."
      so as per the documentation the recommendation is to use serial queue and not locks when a shared resource is involved, but then threading use cases are indeed tricky so using the right tool usually depends on the scenario and the recommended best practices.
      Link: developer.apple.com/library/archive/documentation/General/Conceptual/ConcurrencyProgrammingGuide/OperationQueues/OperationQueues.html
      For async operations yes you may use semaphores to access finite resources but then we have to carefully think about how we are implementing them because yes using them you do handle race conditions gracefully but then we open the doors for deadlock and priority inversion. More details will be shared on the dedicated video of semaphores.
      Semaphore holds a lock on the resource and the issue with that is other operations have to wait in the parking lot unless a signal is received and if your module absolutely requires to have this behavior then yes you should be using semaphore but do plan your design accordingly.
      I will try to cover few portions of this in the API video and then in the semaphore video, would request you to hold me accountable and ask questions like these as it helps me to dig deep into the concepts and explain things much better.