.net - Solution for common async pattern: Start many, await first, cancel the rest -


i'm looking pattern:

let startmanyawaitfirstcancelrest (n:async<'t> list) : async<'t> =     // start n asyncs,     // return result of first finish ,     // cancel rest. 

something this?

open system open system.threading open system.threading.tasks  let run (asyncs: list<async<'t>>): async<'t> =     let cts = new cancellationtokensource()     let tasks = asyncs |> list.map (fun -> async.startastask(a, cancellationtoken = cts.token))     async {         let! t = async.awaittask ((task.whenany tasks).unwrap())         cts.cancel()         return t     } 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -