-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add AsyncSubject #850
Comments
@Blesh @staltz correct me if I'm wrong, but wouldn't it be as simple as this? import {Subject} from '../Subject';
import {Subscriber} from '../Subscriber';
import {Subscription} from '../Subscription';
export class AsyncSubject<T> extends Subject<T> {
_value: T = void 0;
_hasNext: boolean = false;
_isScalar: boolean = true;
constructor () {
super();
}
_subscribe(subscriber: Subscriber<any>): Subscription<T> {
const subscription = super._subscribe(subscriber);
if (!subscription) {
return;
} else if (!subscription.isUnsubscribed && this._hasNext) {
subscriber.next(this._value);
subscriber.complete();
}
return subscription;
}
_next(value: T): void {
this._value = value;
this._hasNext = true;
}
_complete(): void {
let index = -1;
const observers = this.observers;
const len = observers.length;
// optimization -- block next, complete, and unsubscribe while dispatching
this.observers = void 0; // optimization
this.isUnsubscribed = true;
if (this._hasNext) {
while (++index < len) {
observers[index].next(this._value);
observers[index].complete();
}
} else {
while (++index < len) {
observers[index].complete();
}
}
this.isUnsubscribed = false;
}
} |
LGTM. I think once this completes, you could set |
minor thing would be to put |
... also, you'd want to default |
👍 for Just one question: what would be the difference with |
@architruc very different. AsyncSubject does not emit next values before it completes. It only emits on completion, and after completion for late subscribers. |
@staltz Okay, if I understand well Yes, it is different, seems I misunderstood, although |
This can be closed now, I think. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Add AsyncSubject to RxJS v5. Other subjects can be added in the future, but this one is tried and true and used by many community members.
The text was updated successfully, but these errors were encountered: