我使用和来连接到Suave服务器,我有这段代码。我知道服务器是因为邮递员而工作的,并且有一些代码的变体确实调用了服务器。
let AuthUser model : Cmd<LogInMsg> =
let callServer = async {
let! result = server.RequestLogIn model.Credentials
return result
}
let result = callServer |> Async.RunSynchronously
match result with
| LogInFailed x -> Cmd.ofMsg (LogInMsg.LogInRejected x)
| UserLoggedIn x -> Cmd.ofMsg (LogInMsg.LogInSuccess x)let结果中的callServer行在Object(...) is not a function中失败,但我不明白为什么。任何帮助都将不胜感激。
发布于 2018-04-18 13:07:58
根据Fable,Async.RunSynchronously是不受支持的,尽管我不确定这是否导致了您的问题。无论如何,您应该构造代码,这样就不需要阻止异步计算。在Elmish的情况下,您可以使用Cmd.ofAsync创建一个异步命令,在异步完成时分发异步返回的消息。
let AuthUser model : Cmd<LogInMsg> =
let ofSuccess result =
match result with
| LogInFailed x -> LogInMsg.LogInRejected x
| UserLoggedIn x -> LogInMsg.LogInSuccess x
let ofError exn = (* Message representing failed HTTP request *)
Cmd.ofAsync server.RequestLogIn model.Credentials ofSuccess ofError希望这能帮上忙。
https://stackoverflow.com/questions/49891110
复制相似问题