// キューを作成
let cq = new ConcurrentQueue<DataReceivedEventArgs>()
// とあるクラスで標準出力を取得
do ps.OutputDataReceived
|> Event.add ( fun (args :DataReceivedEventArgs) ->
cq.Enqueue(args) |> ignore
)
// (知りたいのはここ!)
member this.sendRecieve(message:string) :string =
// ( その1)emptyのときに永遠に回り続けるので
// 負荷がたかそうな気がする
// (その2)タイムアウトの方法を知りたい
while cq.IsEmpty do
()
snd ( cq.TryDequeue() ) |> fun x -> x.Data
member this.sendRecieve (message:string) :Async<string> = async {
let initialTime = System.TimeSpan.FromMilliseconds(10000.)
let checkTime = 300
cq.Clear |> ignore
ps.StandardInput.WriteLine(message)
// 標準出力の初期出力はなんとなく遅いので
// 多めに待ってあげる
let sw = new System.Diagnostics.Stopwatch();
sw.Start();
while cq.IsEmpty do
if sw.Elapsed > initialTime then
raise (System.ArgumentException("===== foo =====") )
()
// cq.Countが300ms以内に変化がなければ
// 全て出力されたとみなして値を返す
let rec foo () =
let mutable currentCount = cq.Count
Async.Sleep checkTime |> ignore
if currentCount = cq.Count then
snd ( cq.TryDequeue() ) |> fun x -> x.Data
else
foo ()
return ( foo () )
}
InterLocked
使いたかったのですが、実装できませんでした・・・
Thread.Sleep
???
fsc
と lsp
のおかげです!
ギットハブ
アカウント2つで
アカンと(博多弁)