Is there any way to implement dispatch_cancel()?

后端 未结 3 1789
北恋
北恋 2020-12-18 07:40

So far I have gone through the doc of GCD, however it seems there misses dispatch_cancel() which I want to use it to cancel all dispatch\'s blocks invocation. Is there any w

3条回答
  •  感动是毒
    2020-12-18 08:08

    from iOS 8 and higher you can cancel block execution with
    dispatch_block_cancel

    dispatch_block_t blockTask = dispatch_block_create(0,{
     //do some task
    });
    dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW,5*NSEC_PER_SEC);
    dispatch_after(time,dispatch_get_main_queue(),blockTask);
    
    dispatch_block_cancel(blockTask);
    

提交回复
热议问题