What is the significance of WaitUntilDOne in performSelectorOnMainThread?

前端 未结 4 795
攒了一身酷
攒了一身酷 2021-02-15 16:34

What is the significance of WaitUntilDOne in performSelectorOnMainThread?

IN what way the YES or NO set to Wait

4条回答
  •  南旧
    南旧 (楼主)
    2021-02-15 16:59

    From Apple docs about waitUntilDone:

    A Boolean that specifies whether the current thread blocks until after the specified selector is performed on the receiver on the main thread. Specify YES to block this thread; otherwise, specify NO to have this method return immediately. If the current thread is also the main thread, and you specify YES for this parameter, the message is delivered and processed immediately.

    You have to focus on which thread is executing performSelectorOnMainThread. That thread will block and wait until the main thread has completed that selector; say, e.g., that a worker thread needs sending a message to the main thread (e.g., to store some info to some central store which is not thread-safe). The worker might want to block and wait for the operation to complete before issuing another operation of the same kind. So, waitUntilDone come in handy in such case.

提交回复
热议问题