, conditionChecks false. , :
, - async. async , , true. . : , , .
let r = new System.Random()
let rec someCondition1 () =
async {
printfn "Checking condition 1"
if r.Next() % 52 = 0 then
return true
else
return! someCondition1 ()
}
let rec someCondition2 () =
async {
printfn "Checking condition 2"
if r.Next() % 24 = 0 then
return true
else
return! someCondition2 ()
}
let allConditions = [
someCondition1 ()
someCondition2 ()
]
let rec eventLoop () =
printfn "Event loop runs now"
let ready = allConditions |> Async.Parallel |> Async.RunSynchronously
if Array.reduce (&&) ready then
eventLoop()
else
printfn "Some conditions returned false somehow"
, , :
Checking condition 1
Checking condition 1
Checking condition 1
Checking condition 1
Checking condition 1
Checking condition 1
Checking condition 1
Checking condition 1
Checking condition 1
Checking condition 2
Checking condition 2
Checking condition 1
Checking condition 2
Checking condition 1
Checking condition 2
Checking condition 1
Checking condition 1
Checking condition 1
Checking condition 1
Checking condition 1
Checking condition 1
Checking condition 1
Checking condition 1
Checking condition 1
Checking condition 1
Checking condition 1
Checking condition 1
Checking condition 1
Checking condition 1
Event loop runs now
, 2 true - 1 , true. true, .
, , , "" . - , , false, . :
let condition1CanNeverBeTrue () =
r.Next() % 123456789 = 0
let rec someCondition1 () =
async {
if r.Next() % 523452321 = 0 then
return true
else
if condition1CanNeverBeTrue() then
return false
else
return! someCondition1 ()
}
, .
, , , let ready = ... :
let ready = allConditions |> List.map Async.RunSynchronously
, , List.reduce Array.reduce .