开发者

Type problem with Observable.Create from Boo

开发者 https://www.devze.com 2023-02-18 02:27 出处:网络
I\'m trying to use Reactive Extensions from Boo and am running into type problems.Here\'s the basic example:

I'm trying to use Reactive Extensions from Boo and am running into type problems. Here's the basic example:

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)

Th开发者_JS百科e Subscribe here gives a System.InvalidCastException: Cannot cast from source type to destination type. The issue appears to be with how I'm creating the observable, but I've struggled to see where the type problem arises from.

Ideas?


Observable.Create takes Func<IObserver,Action>, but your OnSubscribe accepts an IObservable.

Try this:

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)
0

精彩评论

暂无评论...
验证码 换一张
取 消