Skip to main content
added 6 characters in body
Source Link
Max Koretskyi
  • 106.3k
  • 69
  • 356
  • 524

I think what you're looking for is AsyncSubject. It mimics the promises behavior very well. Here is the description:

The AsyncSubject is a variant where only the last value of the Observable execution is sent to its observers, and only when the execution completes.

Here is how it can be used in your case:

subject = new AsyncSubject(); ready = streamOfData(stuff).first().subscribe(subject); methodOne() { return this.subject.asObservable(); } 

The subject subscribes to the underlying observable returned by the http.getfirst operator and waits until it's complete. It collects all the subscribers but doesn't send any values to them. As soon as the underlying observable completes it remembers the value and sends it to the collected subscribers. All new future subscribers will be immediately passed this stored resolved value.

Here is the simple example that demonstrates that you can subscribe before or after the observable completes:

const subject = new AsyncSubject(); const o = subject.asObservable(); o.subscribe((v) => { console.log(v); }); interval(500).first().subscribe(subject); setTimeout(() => { o.subscribe((v) => { console.log(v); }); }, 2000); 

I think what you're looking for is AsyncSubject. It mimics the promises behavior very well. Here is the description:

The AsyncSubject is a variant where only the last value of the Observable execution is sent to its observers, and only when the execution completes.

Here is how it can be used in your case:

subject = new AsyncSubject(); ready = streamOfData(stuff).first().subscribe(subject); methodOne() { return this.subject.asObservable(); } 

The subject subscribes to the underlying observable returned by the http.get and waits until it's complete. It collects all the subscribers but doesn't send any values to them. As soon as the underlying observable completes it remembers the value and sends it to the collected subscribers. All new future subscribers will be immediately passed this stored resolved value.

Here is the simple example that demonstrates that you can subscribe before or after the observable completes:

const subject = new AsyncSubject(); const o = subject.asObservable(); o.subscribe((v) => { console.log(v); }); interval(500).first().subscribe(subject); setTimeout(() => { o.subscribe((v) => { console.log(v); }); }, 2000); 

I think what you're looking for is AsyncSubject. It mimics the promises behavior very well. Here is the description:

The AsyncSubject is a variant where only the last value of the Observable execution is sent to its observers, and only when the execution completes.

Here is how it can be used in your case:

subject = new AsyncSubject(); ready = streamOfData(stuff).first().subscribe(subject); methodOne() { return this.subject.asObservable(); } 

The subject subscribes to the underlying observable returned by the first operator and waits until it's complete. It collects all the subscribers but doesn't send any values to them. As soon as the underlying observable completes it remembers the value and sends it to the collected subscribers. All new future subscribers will be immediately passed this stored resolved value.

Here is the simple example that demonstrates that you can subscribe before or after the observable completes:

const subject = new AsyncSubject(); const o = subject.asObservable(); o.subscribe((v) => { console.log(v); }); interval(500).first().subscribe(subject); setTimeout(() => { o.subscribe((v) => { console.log(v); }); }, 2000); 
added 2 characters in body
Source Link
Max Koretskyi
  • 106.3k
  • 69
  • 356
  • 524

I think what you're looking for is AsyncSubject. It mimics the promises behavior very well. Here is the description:

The AsyncSubject is a variant where only the last value of the Observable execution is sent to its observers, and only when the execution completes.

Here is how it can be used in your case:

subject = new AsyncSubject(); ready = streamOfData(stuff).first().subscribe(subject); methodOne() { return this.subject.asObservable(); } 

The subject subscribes to the underlying observable returned by the http.get and waits until it's complete. It collects all the subscribers but doesn't send any values to them. As soon as the underlying observable completes it remembers the value and sends it to the collected subscribers. All new future subscribers will be immediately passed this stored resolved value.

Here is the simple example that demonstrates that you can subscribe before or after the observable completes:

const subject = new AsyncSubject(); const o = subject.asObservable(); o.subscribe((v) => { console.log(v); }); ofinterval(1, 2, 3500).first().subscribe(subject); setTimeout(() => { o.subscribe((v) => { console.log(v); }); }, 2000); 

I think what you're looking for is AsyncSubject. It mimics the promises behavior very well. Here is the description:

The AsyncSubject is a variant where only the last value of the Observable execution is sent to its observers, and only when the execution completes.

Here is how it can be used in your case:

subject = new AsyncSubject(); ready = streamOfData(stuff).first().subscribe(subject); methodOne() { return this.subject.asObservable(); } 

The subject subscribes to the underlying observable returned by the http.get and waits until it's complete. It collects all the subscribers but doesn't send any values to them. As soon as the underlying observable completes it remembers the value and sends it to the collected subscribers. All new future subscribers will be immediately passed this stored resolved value.

Here is the simple example that demonstrates that you can subscribe before or after the observable completes:

const subject = new AsyncSubject(); const o = subject.asObservable(); o.subscribe((v) => { console.log(v); }); of(1, 2, 3).first().subscribe(subject); setTimeout(() => { o.subscribe((v) => { console.log(v); }); }, 2000); 

I think what you're looking for is AsyncSubject. It mimics the promises behavior very well. Here is the description:

The AsyncSubject is a variant where only the last value of the Observable execution is sent to its observers, and only when the execution completes.

Here is how it can be used in your case:

subject = new AsyncSubject(); ready = streamOfData(stuff).first().subscribe(subject); methodOne() { return this.subject.asObservable(); } 

The subject subscribes to the underlying observable returned by the http.get and waits until it's complete. It collects all the subscribers but doesn't send any values to them. As soon as the underlying observable completes it remembers the value and sends it to the collected subscribers. All new future subscribers will be immediately passed this stored resolved value.

Here is the simple example that demonstrates that you can subscribe before or after the observable completes:

const subject = new AsyncSubject(); const o = subject.asObservable(); o.subscribe((v) => { console.log(v); }); interval(500).first().subscribe(subject); setTimeout(() => { o.subscribe((v) => { console.log(v); }); }, 2000); 
added 407 characters in body
Source Link
Max Koretskyi
  • 106.3k
  • 69
  • 356
  • 524

I think what you're looking for is AsyncSubject. It mimics the promises behavior very well. Here is the description:

The AsyncSubject is a variant where only the last value of the Observable execution is sent to its observers, and only when the execution completes.

Here is how it can be used in your case:

subject = new AsyncSubject(); ready = streamOfData(stuff).first().subscribe(subject); methodOne() { return this.subject.asObservable(); } 

The subject subscribes to the underlying observable returned by the http.get and waits until it's complete. It collects all the subscribers but doesn't send any values to them. As soon as the underlying observable completes it remembers the value and sends it to the collected subscribers. All new future subscribers will be immediately passed this stored resolved value.

Here is the simple example that demonstrates that you can subscribe before or after the observable completes:

const subject = new AsyncSubject(); const o = subject.asObservable(); o.subscribe((v) => { console.log(v); }); of(1, 2, 3).first().subscribe(subject); setTimeout(() => { o.subscribe((v) => { console.log(v); }); }, 2000); 

I think what you're looking for is AsyncSubject. It mimics the promises behavior very well. Here is the description:

The AsyncSubject is a variant where only the last value of the Observable execution is sent to its observers, and only when the execution completes.

Here is how it can be used in your case:

subject = new AsyncSubject(); ready = streamOfData(stuff).first().subscribe(subject); methodOne() { return this.subject.asObservable(); } 

The subject subscribes to the underlying observable returned by the http.get and waits until it's complete. It collects all the subscribers but doesn't send any values to them. As soon as the underlying observable completes it remembers the value and sends it to the collected subscribers. All new future subscribers will be immediately passed this stored resolved value.

I think what you're looking for is AsyncSubject. It mimics the promises behavior very well. Here is the description:

The AsyncSubject is a variant where only the last value of the Observable execution is sent to its observers, and only when the execution completes.

Here is how it can be used in your case:

subject = new AsyncSubject(); ready = streamOfData(stuff).first().subscribe(subject); methodOne() { return this.subject.asObservable(); } 

The subject subscribes to the underlying observable returned by the http.get and waits until it's complete. It collects all the subscribers but doesn't send any values to them. As soon as the underlying observable completes it remembers the value and sends it to the collected subscribers. All new future subscribers will be immediately passed this stored resolved value.

Here is the simple example that demonstrates that you can subscribe before or after the observable completes:

const subject = new AsyncSubject(); const o = subject.asObservable(); o.subscribe((v) => { console.log(v); }); of(1, 2, 3).first().subscribe(subject); setTimeout(() => { o.subscribe((v) => { console.log(v); }); }, 2000); 
added 12 characters in body
Source Link
Max Koretskyi
  • 106.3k
  • 69
  • 356
  • 524
Loading
minor grammar fix
Source Link
T.J. Crowder
  • 1.1m
  • 201
  • 2k
  • 2k
Loading
added 374 characters in body
Source Link
Max Koretskyi
  • 106.3k
  • 69
  • 356
  • 524
Loading
Source Link
Max Koretskyi
  • 106.3k
  • 69
  • 356
  • 524
Loading