0
我試圖在Python翻譯下面的JavaScript代碼示例:RxPY - 如何使用stop_and_wait?
import Rx from "rx"
let source = Rx.Observable.interval(1000)
.timestamp()
.controlled();
source.stopAndWait().subscribe(
(result) => console.log("onNext: ", result),
(error) => console.log("onError: ", error),
() => console.log("Done!")
);
該片段從RxJS Release Notes拍攝。我的Python解釋如下所示:
from __future__ import print_function
from rx import Observable
source = Observable.interval(1000).timestamp().controlled()
source.stop_and_wait().subscribe(
on_next=lambda x: print("on_next %s" % x),
on_error=lambda e: print("on_error %s" % e)
)
不幸的是,雖然JavaScript版本的作品就好了Python版本失敗歸因於「StopAndWaitObservable」對象有沒有屬性「認購」的事實。