This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const source = instrument(interval(100)); | |
const counted = source.pipe(publish(), refCount()); | |
const a = counted.subscribe(observer("a")); | |
setTimeout(() => a.unsubscribe(), 110); | |
setTimeout(() => counted.subscribe(observer("b")), 120); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const source = instrument(timer(100)); | |
const counted = source.pipe(publish(), refCount()); | |
const a = counted.subscribe(observer("a")); | |
setTimeout(() => a.unsubscribe(), 110); | |
setTimeout(() => counted.subscribe(observer("b")), 120); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const source = instrument(interval(100)); | |
const counted = source.pipe(publish(), refCount()); | |
const a = counted.pipe(take(1)).subscribe(observer("a")); | |
const b = counted.pipe(take(1)).subscribe(observer("b")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function instrument<T>(source: Observable<T>) { | |
return new Observable<T>(observer => { | |
console.log("source: subscribing"); | |
const subscription = source.pipe( | |
tap(value => console.log(`source: ${value}`)), | |
).subscribe(observer); | |
return () => { | |
subscription.unsubscribe(); | |
console.log("source: unsubscribed"); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const source = instrument(interval(100)); | |
const published = source.pipe(publish()); | |
const a = published.pipe(take(1)).subscribe(observer("a")); | |
const b = published.pipe(take(1)).subscribe(observer("b")); | |
const subscription = published.connect(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { concat, defer, Observable, of } from "rxjs"; | |
import { delay, publish } from "rxjs/operators"; | |
function random() { | |
return Math.floor(Math.random() * 100); | |
} | |
const source = concat( | |
defer(() => of(random())), | |
defer(() => of(random())).pipe(delay(1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { defer, Observable, of, Subject } from "rxjs"; | |
import { delay, multicast } from "rxjs/operators"; | |
const source = defer(() => of( | |
Math.floor(Math.random() * 100) | |
)).pipe( | |
delay(0), | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { defer, Observable, of, Subject } from "rxjs"; | |
const source = defer(() => of( | |
Math.floor(Math.random() * 100) | |
)); | |
function observer(name: string) { | |
return { | |
next: (value: number) => console.log(`observer ${name}: ${value}`), | |
complete: () => console.log(`observer ${name}: complete`) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { defer, Observable, of, Subject } from "rxjs"; | |
import { multicast } from "rxjs/operators"; | |
const source = defer(() => of( | |
Math.floor(Math.random() * 100) | |
)); | |
function observer(name: string) { | |
return { | |
next: (value: number) => console.log(`observer ${name}: ${value}`), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, ContentChild } from '@angular/core'; | |
import { map } from 'rxjs/operators'; | |
import { ConnectionService } from './connection.service'; | |
import { FastDirective} from './fast.directive'; | |
import { SlowDirective} from './slow.directive'; | |
@Component({ | |
selector: 'connection', | |
template: ` |
NewerOlder