Created
February 23, 2015 11:12
-
-
Save kjnilsson/35c946e71c4ff2104674 to your computer and use it in GitHub Desktop.
FSharp recursive async function [Leaking likely scenario] + Closure representation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
[<EntryPoint>] | |
let main argv = | |
let create wait = | |
let agent = new MailboxProcessor<_>(fun inbox -> | |
let rec loop () = async { | |
let! msg = inbox.TryReceive wait | |
match msg with | |
| Some _ -> | |
() //no return | |
| None -> | |
return! loop () | |
return! loop () } | |
loop ()) | |
agent | |
let a = create 50 | |
a.Start() | |
a.Post() | |
Console.ReadLine() |> ignore | |
0 | |
(* | |
loop@13-3 | |
loop: Microsoft.FSharp.Core.FSharpFunc<Microsoft.FSharp.Core.Unit,Microsoft.FSharp.Control.FSharpAsync<Microsoft.FSharp.Core.Unit>> | |
builder@: Microsoft.FSharp.Control.FSharpAsyncBuilder | |
loop@7-1<a> | |
wait: int | |
inbox: Microsoft.FSharp.Control.FSharpMailboxProcessor<a> | |
loop: Microsoft.FSharp.Core.FSharpFunc<Microsoft.FSharp.Core.Unit,Microsoft.FSharp.Control.FSharpAsync<Microsoft.FSharp.Core.Unit>> | |
builder@: Microsoft.FSharp.Control.FSharpAsyncBuilder | |
loop@8-2<a> | |
loop: Microsoft.FSharp.Core.FSharpFunc<Microsoft.FSharp.Core.Unit,Microsoft.FSharp.Control.FSharpAsync<Microsoft.FSharp.Core.Unit>> | |
builder@: Microsoft.FSharp.Control.FSharpAsyncBuilder | |
*) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment