简体   繁体   中英

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

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?

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM