Objective c 是否可以将运行模式:beforeDate:与[NSDate dateWithTimeIntervalSinceNow:0]一起使用?
我正在尝试使用中描述的模式,主要是: 在我的单元测试中,我需要“理顺”一些方法的异步流(fx-AFNetworking-requests操作): 这就是我在测试中使用的“强制同步操作”: 如果使用fx dateWithTimeIntervalSinceNow:10,即值大于零(如引用的SO主题和Github注释状态),我会在测试中得到同等的多余有害延迟。如果我设置…SinceNow:0。。。我所有的测试都没有任何延迟,我看不出这个0值有任何问题 苹果博士说:Objective c 是否可以将运行模式:beforeDate:与[NSDate dateWithTimeIntervalSinceNow:0]一起使用?,objective-c,asynchronous,semaphore,nsrunloop,Objective C,Asynchronous,Semaphore,Nsrunloop,我正在尝试使用中描述的模式,主要是: 在我的单元测试中,我需要“理顺”一些方法的异步流(fx-AFNetworking-requests操作): 这就是我在测试中使用的“强制同步操作”: 如果使用fx dateWithTimeIntervalSinceNow:10,即值大于零(如引用的SO主题和Github注释状态),我会在测试中得到同等的多余有害延迟。如果我设置…SinceNow:0。。。我所有的测试都没有任何延迟,我看不出这个0值有任何问题 苹果博士说: Runs the loop once
Runs the loop once, blocking for input in the specified mode until a given date.
If no input sources or timers are attached to the run loop, this method exits immediately and returns NO; otherwise, it returns after either the first input source is processed *or* limitDate is reached.
这个“或”让我猜测是否可以在不影响代码的情况下使用0秒
我也将感谢任何替代使用这种变化的运行模式。。。方法或完全不同的解决方案来解决引用链接中描述的问题。请注意,我仍然不知道原始问题的答案 此问题的中间解决方案(受GHUnit用于测试异步方法的代码启发)是使用小时间间隔,如[runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate DateWithTimeiterValanceNow:0.05] 目前我使用以下循环:
while (dispatch_semaphore_wait(_semaphore, DISPATCH_TIME_NOW))
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.05, YES);
拖延已经过去
while (dispatch_semaphore_wait(_semaphore, DISPATCH_TIME_NOW))
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.05, YES);