4

Is it possible to add a async task in a Serial queue?

I want to know if you create a serial queue, and add some async tasks, does this queue treat these async tasks as sync tasks?

2
  • No, they will be treated as async tasks. You have no control over when they start or finish. If you need to make several async tasks run one at a time, use a semaphore Commented Aug 29, 2017 at 12:10
  • Ok.Thanks. I want to know Enter and Leave in queue is equal to Signal and Wait in semaphore? Commented Aug 30, 2017 at 5:52

1 Answer 1

1

A serial queue will wait for the previous operation to finish.

From the actual documentation:

Serial queues ... execute one task at a time in the order in which they are added to the queue. The currently executing task runs on a distinct thread (which can vary from task to task) that is managed by the dispatch queue. ...

You can have operations that run "async" but they will be serial.

enter image description here enter image description here

In the example from the image "Async on some thread" will always be printed before "sync" because the myQueue is serial

Sign up to request clarification or add additional context in comments.

1 Comment

According to your answer "Serial queues ... execute one task at a time in the order in which they are added to the queue." so if we add an async task to main, it should freeze the view until the task be finished for the sake of "one task at a time". but it does not happen! @Durdu

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.