I have this type:
type Future<'a> () = let mutable _value: 'a option = None member x.Resolve value = if _value.IsSome then failwith "can only resolve once" _value <- Some value member x.IsResolved with get () = _value.IsSome member x.Value with get () = match _value with | Some v -> v | None -> failwith "hasn't resolved yet"
And I need something like this because I have something along the lines of:
let testHttpGet response = let urlFuture = Future<string>() let get url = urlFuture.Resolve url response (get, urlFuture)
Call that function and set the return value of the returned function
let get, urlFuture = testHttpGet "resp"
Call the returned func, thus resolving the Future
let response = get "http://test"
In the end we have the result of the function
response |> should equal "resp"
And we have the value with which the func was called
urlFuture.IsResolved |> should be True urlFuture.Value |> should equal "http://test"
To me this looks like a sound approach but I also have a feeling that something like it must exist in
Here's where I use them.
Here is a fiddle.