Assuming that your interface is declared something like this:
type IMyInterface =
abstract member BeginOperation :
(string * string * string * string * string * string option) ->
IAsyncResult
abstract member EndOperation : IAsyncResult -> string seq
you should be able to create an Async<'T>
using a little helper function like this:
let toAsync (x : IMyInterface) =
let beginAction (callback, values : obj) =
match values with
| :? (string * string * string * string * string * string option) as v ->
x.BeginOperation v
| _ -> failwith "Unexpected values"
Async.FromBeginEnd (beginAction, x.EndOperation)
The inner beginAction
helper function has the signature 'a * obj -> IAsyncResult
, which means that it takes a tuple of the generic type 'a
(in C# it would typically be denoted as T
) and a System.Object
, and returns an IAsyncResult
instance.
For Async.FromBeginEnd
, that's the required signature for the beginAction
.
The interface's EndOperation
method already has the correct signature, so it can be passed in unmodified.
The entire signature of the toAsync
function is IMyInterface -> Async<seq<string>>
.