dispatch_sync on main queue hangs in unit test

前端 未结 5 1094
太阳男子
太阳男子 2020-12-02 11:08

I was having some trouble unit testing some grand central dispatch code with the built in Xcode unit testing framework, SenTestingKit. I managed to boil my problem done to t

5条回答
  •  温柔的废话
    2020-12-02 11:53

    Will you ever get out of house if you must wait for yourself to get out house first? You guessed right! No! :]

    Basically if:

    1. You are on FooQueue. (doesn't have to be main_queue)
    2. You call the method using sync ie in a serial way and want to execute on FooQueue.

    It will never happen for same reason that you will never get out of house!

    It won't ever get dispatched because it has to wait for itself to get off the queue!

提交回复
热议问题