Press CTRL+C or CMD+C to copy the selected text and close this dialog.
Tweet
0 people like it. Like the snippet!
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24:
static member StartChild (computation:Async<'T>,?millisecondsTimeout) = async { let resultCell = new ResultCell<_>() let! ct = getCancellationToken() // ** the below comment is wrong, adding use removes the memory leak ** let innerCTS = new CancellationTokenSource() // innerCTS does not require disposal let ctsRef = ref innerCTS let _reg = ct.Register( (fun _ -> match !ctsRef with | null -> () | otherwise -> otherwise.Cancel()), null) do queueAsync innerCTS.Token (fun res -> ctsRef := null; resultCell.RegisterResult (Ok res, reuseThread=true)) (fun err -> ctsRef := null; resultCell.RegisterResult (Error err,reuseThread=true)) (fun err -> ctsRef := null; resultCell.RegisterResult (Canceled err,reuseThread=true)) computation |> unfake