我是Xamarin的新手,我正在尝试使用F#构建一个简单的Android应用程序.我正在尝试使用异步从REST API加载数据,然后显示它.我知道必须在MainThread上完成与UI的交互,并且有一些内容Activity.RunOnUiThread().我尝试过以下方法:
let onSearch args =
let search = this.FindViewById<EditText>(Resource_Id.search)
let searchResults = this.FindViewById<TextView>(Resource_Id.searchResults)
button.Text <- search.Text
async {
let! results = recipeSearch.GetRecipes search.Text
searchResults.Text <- results
}
|> Async.Start
button.Click.Add onSearch
Run Code Online (Sandbox Code Playgroud)
这会引发与另一个线程中的UI元素交互的异常.还有这个:
let result = async {
let! results = recipeSearch.GetRecipes search.Text
return results
}
|> Async.RunSynchronously
searchResults.Text <- result
Run Code Online (Sandbox Code Playgroud)
击败了做异步的目的
谢谢
我一直在研究使用带有Suave Web服务器的websockets.不幸的是,它没有很好的记录,我设法找到的是:https://github.com/SuaveIO/suave/tree/master/examples/WebSocket
但是,这只显示了响应发出请求的客户端的websocket,我想基本上让套接字响应所有连接的客户端.像聊天服务器的东西.
我过去曾使用过SignalR,但我更愿意为此避免使用它.
那么,我如何让Suave服务器向所有连接的websocket客户端发送数据呢?
我正在努力学习如何正确使用FsCheck,并将其与Expecto集成.如果我使用默认的FsCheck配置,我可以运行属性测试,但是当我尝试使用自己的Generator时,它会导致堆栈溢出异常.
这是我的发电机
type NameGen() =
static member Name() =
Arb.generate<string * string>
|> Gen.where (fun (firstName, lastName) ->
firstName.Length > 0 && lastName.Length > 0
)
|> Gen.map (fun (first, last) -> sprintf "%s %s" first last)
|> Arb.fromGen
|> Arb.convert string id
Run Code Online (Sandbox Code Playgroud)
而我正试图像这样使用它:
let config = { FsCheckConfig.defaultConfig with arbitrary = [typeof<NameGen>] }
let propertyTests input =
let output = toInitials input
output.EndsWith(".")
testPropertyWithConfig config "Must end with period" propertyTests
Run Code Online (Sandbox Code Playgroud)
在它进入Gen.where函数之前抛出异常
我究竟做错了什么?谢谢