Is there any reason to not use sleep in a Grand Central Dispatch queue?

前端 未结 3 2003
北恋
北恋 2021-02-19 11:35

I would like to make a queue wait for a short period while it is looping. I am considering my options and was testing out suspending a resuming a queue but that seems to require

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-19 12:22

    You can use sleep, but as you mentioned, do it off of the main thread, as you should never tie up the main thread.

    But, if you need a small sleep, the amount of time may not be precise, and is unlikely to be, but the thread will be woken up at least after the amount of sleep, depending on what else may be using the cpu.

    But, I see no problem with using sleep as it will at least give other threads/applications, a chance to run.

提交回复
热议问题