Create disposal function

Category:
Disposal
Description: Create disposal function
Code:
let DisposalSample2() = 
let createDisposable f =
{
new IDisposable with
member x.Dispose() = f()
}
let test () =
using (createDisposable (fun _ -> printfn "disposed" )) (fun _ -> printfn "inside")
test()
printfn "finished"

//--------------------------------------------------------

Execution Result:
inside
disposed
finished

Last edited Sep 14, 2011 at 2:32 AM by ttliu2000, version 1

Comments

No comments yet.