In unit test, execute the block passed in queue with dispatch_asyc

前端 未结 2 1269
感情败类
感情败类 2021-02-11 10:12

If I dispatch_async a block on main queue like this:

-(void) myTask {
  dispatch_async(dispatch_get_main_queue(), ^{
      [self.se         


        
2条回答
  •  悲哀的现实
    2021-02-11 10:35

    You could create the queue in your test function.

    -(void) myTask2:(dispatch_queue_t*)queue {
        dispatch_async(*queue, ^{
            [self.service fetchData];
        });
    }
    
    -(void)testMyTask2{
        dispatch_queue_t queue = dispatch_queue_create("my.sequential.queue", NULL);
        [myObj myTask2:&queue];
    
        dispatch_sync(queue, ^{
        });
    }
    

    (Just realised currentRunLoop is not needed)

提交回复
热议问题