Tipo de problema con Observable.Create de Boo
-
27-10-2019 - |
Pregunta
Estoy tratando de utilizar reactiva Extensiones de Boo y estoy corriendo en problemas de tipo. Aquí está el ejemplo básico:
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)
La Suscribirse aquí da una System.InvalidCastException: no puede lanzar desde el tipo de fuente de tipo de destino. El problema parece ser con la forma en que estoy creando lo observable, pero he luchado para ver donde surge el problema de tipo.
Las ideas?
Solución
Observable.Create
toma Func<IObserver,Action>
, pero su OnSubscribe
acepta una IObservable
.
Prueba esto:
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)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow