Subject
で公開されている問題のビットがRx.Observable.webSocket
で公開されています。 complete
の後にWebSocketが再接続されると、ソケット上に来る次のメッセージをプッシュするのではなく、Subject
へのその後のサブスクリプションもすぐに完了します。Rx.Observable.webSocket()は再接続後すぐに完了しますか?
私は、これがどのように機能するのかについて何か基本的なものが欠けていると思います。
ここにはrequirebin/pasteがあります。これは、私が意味することと、私が期待していた振る舞いを少し良く表してくれることを願っています。それは私が見落とした超簡単な何かになると思う。
var Rx = require('rxjs')
var subject = Rx.Observable.webSocket('wss://echo.websocket.org')
subject.next(JSON.stringify('one'))
subject.subscribe(
function (msg) {
console.log('a', msg)
},
null,
function() {
console.log('a complete')
}
)
setTimeout(function() {
subject.complete()
}, 1000)
setTimeout(function() {
subject.next(JSON.stringify('two'))
}, 3000)
setTimeout(function() {
subject.next(JSON.stringify('three'))
subject.subscribe(
function (msg) {
// Was hoping to get 'two' and 'three'
console.log('b', msg)
},
null,
function() {
// Instead, we immediately get here.
console.log('b complete')
}
)
}, 5000)
あなたは冷たい観測対ホットに対処されるかもしれないような音。 https://github.com/Reactive-Extensions/RxJS/blob/master/doc/gettingstarted/creating.md#cold-vs-hot-observables – emc