I am trying to subscribe / unsubscribe to a C#-made (in the RabbitMQ client library) from F#:
public event AsyncEventHandler<BasicDeliverEventArgs> Received;
public delegate Task AsyncEventHandler<in TEvent>(object sender, TEvent @event) where TEvent : EventArgs;
I managed to subscribe to the event by doing:
let subscribeAsync (channel: IModel) exchange callback =
let consumer = AsyncEventingBasicConsumer(channel)
consumer.add_Received(AsyncEventHandler<BasicDeliverEventArgs>(fun sender args -> Task.CompletedTask))
// ...
That being said, I'm wondering why the code below cannot compile:
let subscribeAsync (channel: IModel) exchange callback =
let consumer = AsyncEventingBasicConsumer(channel)
consumer.Received.AddHandler(AsyncEventHandler<BasicDeliverEventArgs>(fun sender args -> Task.CompletedTask))
// ...
Cause I get the error below:
Program.fs(10, 14): [FS1091] The event 'Received' has a non-standard type. If this event is declared in another CLI language, you may need to access this event using the explicit add_Received and remove_Received methods for the event. If this event is declared in F#, make the type of the event an instantiation of either 'IDelegateEvent<_>' or 'IEvent<_,_>'.
I checked the official MS documentation but I can't see any reference to what is a standard event type for F#.