typescript - rxJs Subject, error in subscriptions kills the whole stream -
i know known behavior desribed here
basic problem described in link above, here relevant code (taken link)
// going behave strangely const source$ = observable.interval(1000).share(); const mapped$ = source$.map(x => { if (x === 1) { throw new error('oops'); } return x; }); source$.subscribe(x => console.log('a', x)); mapped$.subscribe(x => console.log('b', x)); source$.subscribe(x => console.log('c', x)); // "a" 0 // "b" 0 // "c" 0 // "a" 1 // uncaught error: "oops"
an error in subscription terminate whole source stream.
the solution observable use .observeon(rx.scheduler.asap);
i'm new whole reactive programming , struggle apply solution subject
because subject doesn't support observeon
.
but need subject
because need push new values steam.
how can workaround problem or use observeon
subject
?
observeon
returns observable
. struggle how combine observeon
subject
. how use observeon , still able push values subject?
here's current code (simplified)
export class myclass{ private messages: subject<message> = new subject<message>(); dispatchmessage(message: message) { this.messages.next(message); }
ideas?
p.s.
for using angular (like me), observeon might have undesired side effects. https://github.com/angular/angular/issues/14316
just additional information comes question.
in case need separate reference subject
reference chain after append observeon
operator:
const subject$ = new subject(); const obs$ = subject$.observeon(...); obs$.subscribe(...); subject$.next(...);
Comments
Post a Comment