Tapez un problème Observable.Create de Boo
-
27-10-2019 - |
Question
Je suis en train d'utiliser Reactive Extensions de Boo et je suis en cours d'exécution dans des problèmes de type. Voici l'exemple de base:
def OnSubscribe(observer as IObservable[of string]) as callable:
print "subscribing"
def Dispose():
print "disposing"
return Dispose
observable = System.Linq.Observable.Create[of string](OnSubscribe)
observer = System.Linq.Observer.Create[of string]({x as string | print x})
observable.Subscribe(observer)
Le ABONNEMENTS donne une System.InvalidCastException: ne peut pas lancer de type source au type de destination. La question semble être la façon dont je crée l'observable, mais je l'ai eu du mal à voir où se pose le problème de type.
Idées?
La solution
Observable.Create
prend Func<IObserver,Action>
, mais votre OnSubscribe
accepte un IObservable
.
Essayez ceci:
def OnSubscribe(observer as IObserver[of string]) as callable():
print "subscribing"
observer.OnNext("first and only value")
observer.OnCompleted()
def Dispose():
print "disposing"
return Dispose
observable = System.Linq.Observable.Create[of string](OnSubscribe)
observer = System.Linq.Observer.Create[of string]({x as string | print x})
observable.Subscribe(observer)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow