Followed Functional Reactive Programming tutorial, where stream of events (Observable) is directly created from System.Timers.Timer.Elapsed event.
let timer = new System.Timers.Timer(float 1)
let observable = timer.Elapsed
observable
|> Observable.subscribe ...
Have class defined in C#
public delegate void OnMessageDelegate(Message message);
public class Notifier : INotifier
{
public event OnMessageDelegate OnMessage;
public void Notify(Message message)
=> OnMessage?.Invoke(message);
}
Referenced corresponding .dll into F# project and trying to create Observable from Notifier.OnMessage event
let Start (notifier : Namespace.Notifier) =
notifier.OnMessage
|> Observable.subscribe (fun ms -> ...
0
Getting error message
The event
OnMessagehas a non-standard type. If this event is declared in another CLI language, you may need to access this event using the explicitadd_OnMessageandremove_OnMessagemethods for the event. If this event is declared in F#, make the type of the event an instantiation of eitherIDelegateEvent<_>orIEvent<_,_>.
The error message is self descriptive, though I aim to create stream from event and not to subscribe on it via add_OnMessage method.
It appears that F# expects the delegate type for events to be System.EventHandler or a specialization of System.EventHandler<'TEventArgs>.
Try changing the type of OnMessage from OnMessageDelegate to EventHandler<Message>.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With