Observer subscribing to ConnectableObservable didn't get notified after connect method
up vote
0
down vote
favorite
Console print nothing after excuting these code
ConnectableObservable o = ConnectableObservable.create(emitter -> {
emitter.onNext("first");
Thread.sleep(6000);
emitter.onNext("second");
}).publish();
o.connect();
o.subscribe(
msg -> Log.i(TAG, "" + msg),
throwable -> Log.e(TAG, "", (Throwable) throwable)
);
But the doc said
You can also use the connect method to instruct an Observable to begin emitting items (or, to begin generating items that would be emitted) even before any Subscriber has subscribed to it.
rx-java rx-java2
add a comment |
up vote
0
down vote
favorite
Console print nothing after excuting these code
ConnectableObservable o = ConnectableObservable.create(emitter -> {
emitter.onNext("first");
Thread.sleep(6000);
emitter.onNext("second");
}).publish();
o.connect();
o.subscribe(
msg -> Log.i(TAG, "" + msg),
throwable -> Log.e(TAG, "", (Throwable) throwable)
);
But the doc said
You can also use the connect method to instruct an Observable to begin emitting items (or, to begin generating items that would be emitted) even before any Subscriber has subscribed to it.
rx-java rx-java2
You have a synchronous source that sleeps whenconnect
gets called so you will miss both of its items when usingpublish
. Consider usingreplay()
.
– akarnokd
Nov 8 at 9:27
you' re right, thank you
– Jason Wang
Nov 8 at 13:32
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Console print nothing after excuting these code
ConnectableObservable o = ConnectableObservable.create(emitter -> {
emitter.onNext("first");
Thread.sleep(6000);
emitter.onNext("second");
}).publish();
o.connect();
o.subscribe(
msg -> Log.i(TAG, "" + msg),
throwable -> Log.e(TAG, "", (Throwable) throwable)
);
But the doc said
You can also use the connect method to instruct an Observable to begin emitting items (or, to begin generating items that would be emitted) even before any Subscriber has subscribed to it.
rx-java rx-java2
Console print nothing after excuting these code
ConnectableObservable o = ConnectableObservable.create(emitter -> {
emitter.onNext("first");
Thread.sleep(6000);
emitter.onNext("second");
}).publish();
o.connect();
o.subscribe(
msg -> Log.i(TAG, "" + msg),
throwable -> Log.e(TAG, "", (Throwable) throwable)
);
But the doc said
You can also use the connect method to instruct an Observable to begin emitting items (or, to begin generating items that would be emitted) even before any Subscriber has subscribed to it.
rx-java rx-java2
rx-java rx-java2
asked Nov 8 at 9:21
Jason Wang
21
21
You have a synchronous source that sleeps whenconnect
gets called so you will miss both of its items when usingpublish
. Consider usingreplay()
.
– akarnokd
Nov 8 at 9:27
you' re right, thank you
– Jason Wang
Nov 8 at 13:32
add a comment |
You have a synchronous source that sleeps whenconnect
gets called so you will miss both of its items when usingpublish
. Consider usingreplay()
.
– akarnokd
Nov 8 at 9:27
you' re right, thank you
– Jason Wang
Nov 8 at 13:32
You have a synchronous source that sleeps when
connect
gets called so you will miss both of its items when using publish
. Consider using replay()
.– akarnokd
Nov 8 at 9:27
You have a synchronous source that sleeps when
connect
gets called so you will miss both of its items when using publish
. Consider using replay()
.– akarnokd
Nov 8 at 9:27
you' re right, thank you
– Jason Wang
Nov 8 at 13:32
you' re right, thank you
– Jason Wang
Nov 8 at 13:32
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53204713%2fobserver-subscribing-to-connectableobservable-didnt-get-notified-after-connect%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
You have a synchronous source that sleeps when
connect
gets called so you will miss both of its items when usingpublish
. Consider usingreplay()
.– akarnokd
Nov 8 at 9:27
you' re right, thank you
– Jason Wang
Nov 8 at 13:32