Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define an async f# interface that can be implemented in c#?

Tags:

c#

f#

I have defined an interface in F#

type IConnect =
    abstract Update: seq<DataType> -> Async<bool>

I would like other apps in the same appdomain to implement it so that I can call Update on any that implement the interface (I gather the implementations in an TinyIoC container). The return type Async<bool> can indicate if the update succeeded or not without having to wait for it. And I can update the apps in parallel.

The other apps are written in c# and when I started to write a reference (mock) implementation I realised that this would require any implementer to use a FSharpAsync type which is not very pretty.

So, how do I define the interface so that it is easy to implement in c# and keep the async aspects?

like image 560
Remko Avatar asked Oct 21 '22 08:10

Remko


1 Answers

Use Task or perhaps IObservable. You can convert between async workflows and Task<T> quite easily and it is a simple type to work with in C# or most .Net languages.

type IConnect = abstract Update: seq<DataType> -> Task<bool>
like image 97
Leaf Garland Avatar answered Oct 24 '22 10:10

Leaf Garland