在ios中创建异步串行队列

时间:2013-06-03 13:33:54

标签: ios objective-c grand-central-dispatch

我需要创建一个异步执行的队列,但任务执行的顺序必须是串行的

dispatch_queue_t queue;
queue = dispatch_queue_create("com.test.app", NULL); //create a serial queue can either be null or DISPATCH_QUEUE_SERIAL

dispatch_async(queue,
                ^{

                //Mycode for doing background http

                }

1 个答案:

答案 0 :(得分:4)

我认为你正确地做到了,

dispatch_queue_t queue;
queue = dispatch_queue_create("com.test.app", NULL); //create a serial queue can either be null or DISPATCH_QUEUE_SERIAL

dispatch_async(queue,
                ^{
task1;
task2;
...

all this tasks wil be done done sequentially 


                }