使 Foundation dispatch_xxx_ 函数在测试中正常同步运行异步代码
围绕 dispatch queue 添加了一系列方法,当在测试目标中运行时将同步执行,但在应用程序目标中则异步执行。已测试。
/// Async in App Code, sync in Test Code, waits for a time then runs the block on the main queue
extern void ar_dispatch_after(NSTimeInterval time, dispatch_block_t block);
/// Async in App Code, sync in Test Code, waits for a time then runs the block on your own queue
extern void ar_dispatch_after_on_queue(NSTimeInterval time, dispatch_queue_t queue, dispatch_block_t block);
/// Async in App Code, sync in Test Code, runs a block on a default queue on another thread
extern void ar_dispatch_async(dispatch_block_t block);
/// Async in App Code, sync in Test Code, runs a block on the main thread
extern void ar_dispatch_main_queue(dispatch_block_t block);
/// Async in App Code, sync in Test Code, runs block on a queue
extern void ar_dispatch_on_queue(dispatch_queue_t queue, dispatch_block_t block);
要运行示例项目,克隆仓库,并从 Example 目录中首先运行 pod install
。
Orta Therox,[email protected]
ar_dispatch 在 MIT 许可协议下提供。有关更多信息,请参阅 LICENSE 文件。