How do you schedule a block to run on the next run loop iteration?

后端 未结 5 2353
隐瞒了意图╮
隐瞒了意图╮ 2020-12-02 04:36

I want to be able to execute a block on the next run loop iteration. It\'s not so important whether it gets executed at the beginning or the end of the next run

5条回答
  •  旧时难觅i
    2020-12-02 05:09

    I do not believe there is any API that will allow you to guarantee code gets run on the very next event loop turn. I'm also curious why you need a guarantee that nothing else has run on the loop, the main one in particular.

    I can also confirm that using the perforSelector:withObject:afterDelay does use a runloop-based timer, and will have functionally similar behavior to dispatch_async'ing on dispatch_get_main_queue().

    edit:

    Actually, after re-reading your question, it sounds like you only need the current runloop turn to complete. If that is true, then dispatch_async is exactly what you need. In fact, all of the code above does make the guarantee that the current runloop turn will complete.

提交回复
热议问题