Domanda

Sto cercando di utilizzare le estensioni reattiva da Boo e sto incorrere in problemi di tipo. Ecco l'esempio di 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)

L'Iscriviti qui dà una System.InvalidCastException: non può lanciare dal tipo di origine al tipo di destinazione. Il problema sembra essere di come sto creando il osservabile, ma ho faticato a vedere dove il problema nasce dal tipo.

idee?

È stato utile?

Soluzione

Observable.Create prende Func<IObserver,Action>, ma la vostra OnSubscribe accetta un IObservable.

Prova questo:

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)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top