Observable.Create from Boo 的类型问题

发布于 2024-10-23 13:03:15 字数 513 浏览 9 评论 0原文

我正在尝试使用 Boo 的反应式扩展,但遇到了类型问题。这是基本示例:

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)

此处的 Subscribe 给出了 System.InvalidCastException:无法从源类型转换为目标类型。问题似乎在于我如何创建可观察的,但我一直在努力找出类型问题的根源。

有想法吗?

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)

The 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夕色琉璃 2024-10-30 13:03:15

Observable.Create 采用 Func,但您的 OnSubscribe 接受 IObservable

试试这个:

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)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文