英文:
All Swift BrightFuture callbacks happen on the main thread, right?
问题
当我们使用BrightFutures进行异步请求时,相应的...
代码块会在哪个线程上运行?
我的理解是它们将始终在main
线程上运行,对吗?
英文:
When we make an asynchronous request using BrightFutures.
service.makeSomeRequest(
param1: value1,
param2: value2
)
.onSuccess { [weak self] result in
...
}
.onFailure { [weak self] error in
...
}
Which threading context will the respective ...
blocks run in?
My understanding is that they will always be on main
thread, right?
答案1
得分: 0
不要紧,找到这篇有用的文章,记录了预期的行为:
-
如果该方法从主线程调用,该块将在主队列上执行
-
如果该方法不是从主线程调用,该块将在全局队列上执行
所以基本上,.onSuccess(...)
和 .onFailure(...)
回调的执行上下文取决于调用 service.makeSomeRequest(...)
时的原始上下文。
英文:
Nevermind, found this helpful article documenting the expected behavior:
-
If the method is called from the main thread, the block is executed on the main queue
-
If the method is not called from the main thread, the block is executed on a global queue
So basically, the context in which the .onSuccess(...)
and .onFailure(...)
callbacks will be executed depends on the original context in which the service.makeSomeRequest(...)
was called.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论