3
我需要在后台调用一个调用web服务的API。我不希望将(非常复杂的)方法变成异步,只是说“在后台执行所有操作”。在F#中如何在后台运行阻塞调用?
但我失去了如何与F#这一点。这是我有:
let task = async {
let result = SyncApi.syncData(login.url, login.zone, login.user, login.pwd) <-- THIS MUST RUN IN BACKGROUND...
match result with
|Some(msg) -> failwith msg
| None ->()
}
task
|> Async.Catch
|> Async.RunSynchronously
|> fun x ->
match x with
| Choice1Of2 x -> rootPage.Navigation.PopToRootAsync(true) |> ignore
| Choice2Of2 ex -> showMsgError(ex.Message)
不,我不能忽略错误并离开。 – mamcx
为什么你需要*首先在背景上调用API?如果要在处理期间使UI响应,但不能异步显示错误消息,恐怕除了让整个方法异步外,别无他法。如果您想使该方法更快,那么显示错误的同步点就是问题 - 它不会消失,它必须等待处理结果。 –
是的是让UI响应。在swift中很容易做到这一点,我只是安排在另一个线程的任务︰https://stackoverflow.com/questions/24056205/how-to-use-background-thread-in-swift – mamcx