rxjs#interval TypeScript Examples
The following examples show how to use
rxjs#interval.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: api.service.ts From EXOS-Core with MIT License | 6 votes |
/**
* Get wallet balance info from the API.
*/
getWalletBalance(data: WalletInfo): Observable<any> {
const search = new HttpParams({
fromObject: {
walletName: data.walletName,
accountName: 'account 0'
}
});
return interval(this.pollingInterval)
.pipe(startWith(0))
.pipe(switchMap(() => this.http.get(this.apiUrl + '/wallet/balance', { headers: this.headers, params: search })))
.pipe(catchError(this.handleError.bind(this)))
.pipe(map((response: Response) => response));
}
Example #2
Source File: api.service.ts From blockcore-hub with MIT License | 6 votes |
getBannedNodesCustomInterval(milliseconds: number): Observable<any> {
const self = this;
return interval(milliseconds)
.pipe(startWith(0))
.pipe(switchMap(() => this.http.get(self.apiUrl + '/Network/getbans', { headers: self.headers })))
.pipe(catchError(this.handleError.bind(this)))
.pipe(map((response: Response) => response));
}
Example #3
Source File: app-bar.component.ts From angular-component-library with BSD 3-Clause "New" or "Revised" License | 6 votes |
private _listenForScrollEvents(): void {
this._setScrollEl();
this._resizeOnModeChange();
this._stopListeningForScrollEvents();
this.viewInit = true;
if (this.scrollEl) {
this.scrollListener = fromEvent(this.scrollEl, 'scroll')
.pipe(throttle(() => interval(10)))
.subscribe(() => {
this._resizeEl();
});
this.resizeListener = fromEvent(window, 'resize')
.pipe(throttle(() => interval(10)))
.subscribe(() => {
this._resizeEl();
});
}
}
Example #4
Source File: load.component.ts From EXOS-Core with MIT License | 6 votes |
private startTimer(seconds: number) {
const time = seconds;
const timer$ = interval(1000);
const sub = timer$.subscribe((sec) => {
this.progressbarValue = 0 + sec * 90 / seconds;
this.curSec = sec;
if (this.curSec === seconds) {
if (this.moduleState === 'Initialized') {
this.progressbarValue = 100;
}
sub.unsubscribe();
}
if (!this.loading) { sub.unsubscribe(); }
});
}
Example #5
Source File: api.service.ts From blockcore-hub with MIT License | 6 votes |
/**
* Get staking info
*/
getStakingInfo(): Observable<any> {
return interval(this.pollingInterval)
.pipe(startWith(0))
.pipe(switchMap(() => this.http.get(this.apiUrl + '/staking/getstakinginfo')))
.pipe(catchError(this.handleError.bind(this)))
.pipe(map((response: Response) => response));
}
Example #6
Source File: api.service.ts From EXOS-Core with MIT License | 6 votes |
/**
* Get a wallets transaction history info from the API.
*/
getWalletHistory(data: WalletInfo): Observable<any> {
const search = new HttpParams({
fromObject: {
walletName: data.walletName,
accountName: 'account 0'
}
});
return interval(this.longPollingInterval)
.pipe(startWith(0))
.pipe(switchMap(() => this.http.get(this.apiUrl + '/wallet/history', { headers: this.headers, params: search })))
.pipe(catchError(this.handleError.bind(this)))
.pipe(map((response: Response) => response));
}
Example #7
Source File: analysis-progress.page.ts From geonetwork-ui with GNU General Public License v2.0 | 6 votes |
ngOnInit(): void {
this.subscription = new Subscription()
this.statusFetch$ = this.activatedRoute.params.pipe(
mergeMap(({ id }) =>
interval(500).pipe(
switchMap(() => this.fileUploadApiService.findUploadJob(id)),
tap((job: UploadJobStatusApiModel) => this.facade.setUpload(job)),
tap((job: UploadJobStatusApiModel) => (this.progress = job.progress)),
filter(
(job: UploadJobStatusApiModel) =>
![Pending, Analyzing].includes(job.status)
),
take(1)
)
)
)
this.subscription.add(
this.statusFetch$.subscribe((job: UploadJobStatusApiModel) =>
this.onJobFinish(job)
)
)
}
Example #8
Source File: tour-backdrop.service.ts From ngx-ui-tour with MIT License | 6 votes |
private subscribeToWindowResizeEvent() {
const resizeObservable$ = fromEvent(window, 'resize');
this.windowResizeSubscription$ = resizeObservable$
.pipe(
debounce(() => interval(10))
)
.subscribe(
() => {
this.setBackdropElStyles();
ScrollingUtil.ensureVisible(this.targetHtmlElement);
}
);
}
Example #9
Source File: app.service.ts From ngx-htaccess-generator with MIT License | 6 votes |
constructor() {
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
this.lastDarkModeActive = true;
}
this.subscrManager.add(interval(1000).subscribe(() => {
const darkModeActiveNow = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
if (!this.lastDarkModeActive && darkModeActiveNow) {
console.log(`dark mode detected`);
this.lastDarkModeActive = true;
} else if (this.lastDarkModeActive && !darkModeActiveNow) {
this.lastDarkModeActive = false;
}
}));
}
Example #10
Source File: app.component.ts From aws-power-tuner-ui with Apache License 2.0 | 6 votes |
startPolling(token: PowerTunerToken) {
this.executionToken = token.executionToken;
this.formGroup.controls.executionId.setValue(this.executionToken);
localStorage.setItem('token', this.executionToken);
const subject = new Subject<string>();
let attempt = 0;
this.trackedSubscriptions.push(interval(5000)
.pipe(
startWith(0),
take(24),
takeUntil(subject),
switchMap(() => this.httpService.fetchPowerTunerStepFunction(token))
)
.subscribe(
ratesResult => {
attempt += 1;
if (this.checkStatusToEndPolling(ratesResult.status)) {
if (ratesResult.status === 'SUCCEEDED') {
this.processResults(JSON.parse(ratesResult.output));
this.resultsBack = true;
this.resultsProcessing = false;
} else {
this.resultsError = true;
this.resetTuner();
}
subject.next('Finished');
}
if (attempt >= 24) {
subject.next('Finished');
}
},
error => {
this.processErrorResults(error);
subject.next('Error');
}
));
}
Example #11
Source File: hold-delete.directive.ts From tabby with MIT License | 6 votes |
@HostListener('mousedown', ['$event'])
onHold() {
// console.log('%c started hold', 'color: #5fba7d; font-weight: bold;')
this.state.next('start')
const n = 100;
interval(n).pipe(
takeUntil(this.cancel),
tap(v => {
this.holdTime.emit(v * n)
}),
)
.subscribe();
}
Example #12
Source File: app.component.ts From ngrx-issue-tracker with MIT License | 6 votes |
constructor(private store: Store) {
this.stats$ = this.store.select(fromIssue.selectStats);
this.navigationLoading$ = this.store
.select(fromNavigation.selectLoading)
.pipe(
// delay spinner deactivation, so we can see the spinner for a bit
delayWhen((loading) => interval(loading ? 0 : 500))
);
}
Example #13
Source File: SetInterval.tsx From grafana-chinese with Apache License 2.0 | 6 votes |
componentDidMount() {
// Creating a subscription to propsSubject. This subject pushes values every time
// SetInterval's props change
this.subscription = this.propsSubject
.pipe(
// switchMap creates a new observables based on the input stream,
// which becomes part of the propsSubject stream
switchMap(props => {
// If the query is live, empty value is emited. `of` creates single value,
// which is merged to propsSubject stream
if (RefreshPicker.isLive(props.interval)) {
return of({});
}
// When query is loading, a new stream is merged. But it's a stream that emits no values(NEVER),
// hence next call of this function will happen when query changes, and new props are passed into this component
// When query is NOT loading, a new value is emited, this time it's an interval value,
// which makes tap function below execute on that interval basis.
return props.loading ? NEVER : interval(stringToMs(props.interval));
}),
// tap will execute function passed via func prop
// * on value from `of` stream merged if query is live
// * on specified interval (triggered by values emited by interval)
tap(() => this.props.func())
)
.subscribe();
// When component has mounted, propsSubject emits it's first value
this.propsSubject.next(this.props);
}
Example #14
Source File: activity.component.ts From tzcolors with MIT License | 6 votes |
async ngOnInit(): Promise<void> {
wrapApiRequest('fetchOperations', () => {
return this.fetchOperations()
})
this.subscription.add(
combineLatest([this.storeService.colors$, this.operations]).subscribe(
([colors, operations]) => {
const mapColors = mapOps(colors)
this.activities = operations.map(mapColors).filter(isActivityItem)
}
)
)
this.subscription.add(
interval(60_000).subscribe((x) => {
wrapApiRequest('fetchOperations', () => {
return this.fetchOperations()
})
})
)
}
Example #15
Source File: api.service.ts From blockcore-hub with MIT License | 6 votes |
getNodeStatusInterval(): Observable<any> {
const self = this;
return interval(this.pollingInterval)
.pipe(startWith(0))
.pipe(switchMap(() => this.http.get(self.apiUrl + '/node/status', { headers: self.headers })))
.pipe(catchError(this.handleError.bind(this)))
.pipe(map((response: Response) => response));
}
Example #16
Source File: promo-code-api.service.ts From rubic-app with GNU General Public License v3.0 | 6 votes |
/**
* Sets revalidation interval.
* @param revalidationTimeout promo code data refreshing interval.
*/
private setInterval(revalidationTimeout: number): void {
this.interval$ = interval(revalidationTimeout);
this.intervalSubscription$ = this.interval$
.pipe(
map(() => this.settingsService.crossChainRoutingValue.promoCode?.text),
filter(promoCodeText => !!promoCodeText),
switchMap(promoCodeText => this.getPromoCodeByText(promoCodeText))
)
.subscribe(promoCode => this.settingsService.crossChainRouting.patchValue({ promoCode }));
}
Example #17
Source File: connection.service.ts From RcloneNg with MIT License | 6 votes |
constructor(
currentUserService: CurrentUserService,
private browserSettingService: BrowserSettingService
) {
this.timer = browserSettingService
.partialBrowserSetting$('rng.request-interval')
.pipe(switchMap(([int, err]) => interval(int)));
const outer = this;
this.rst$ = new (class extends NoopAuthFlow {
public prerequest$ = combineLatest([
outer.timer,
currentUserService.currentUserFlow$.getOutput(),
]).pipe(map(x => x[1]));
})();
this.rst$.deploy();
this.connection$ = new (class extends ConnectionFlow {
public prerequest$: Observable<CombErr<NoopAuthFlowSupNode>> = outer.rst$.getSupersetOutput();
})();
this.connection$.deploy();
this.listCmd$ = new (class extends ListCmdFlow {
public prerequest$ = outer.connection$.getSupersetOutput();
})();
this.listCmd$.deploy();
}
Example #18
Source File: carousel.component.ts From canopy with Apache License 2.0 | 6 votes |
setAutoPlayInterval(): void {
this.pausableTimer$ = defer(() => {
return interval(this.autoPlayDelay).pipe(
takeUntil(this.unsubscribe),
withLatestFrom(this.pause),
filter(([ , paused ]) => !paused),
map(() => this.nextCarouselItem()),
);
});
this.pausableTimer$.subscribe();
this.cd.detectChanges();
}
Example #19
Source File: app.component.ts From Angular-Cookbook with MIT License | 6 votes |
startStream() {
const streamSource = interval(1500);
const cartoonStreamSource = interval(1000).pipe(
map((output) => output % this.cartoonsStreamData.length),
map((index) => this.cartoonsStreamData[index])
);
this.subscription = streamSource
.pipe(
map((output) => output % this.inputStreamData.length),
map((index) => this.inputStreamData[index]),
merge(cartoonStreamSource)
)
.subscribe((element) => {
this.outputStreamData.push(element);
});
}
Example #20
Source File: scanned-item-manager.service.ts From pantry_party with Apache License 2.0 | 6 votes |
private timerTick = interval(1000).pipe(
takeUntil(this.ngUnsubscribe),
map(_ => this._scannedItems.forEach(i => {
if (this.elgibleForSave(i) && i.saveCoutdown > 1) {
this.updateScannedItemWithoutVersionBump(
i.barcode,
{saveCoutdown: i.saveCoutdown - 1}
);
} else if (!i.saveInProgress && this.elgibleForSave(i) && i.saveCoutdown <= 1) {
this.perfomSave(i);
}
}))
).subscribe();
Example #21
Source File: broker-gateway.ts From scion-microfrontend-platform with Eclipse Public License 2.0 | 6 votes |
/**
* Installs a scheduler that periodically sends a heartbeat to indicate that this client is connected to the host.
*
* Note that no heartbeat scheduler is installed if running in the context of the host application.
*/
private installHeartbeatPublisher(brokerInfo: BrokerInfo): void {
if (Beans.get(IS_PLATFORM_HOST)) {
return; // The host app client does not send a heartbeat.
}
interval(brokerInfo.heartbeatInterval)
.pipe(takeUntil(this._platformStopping$))
.subscribe(() => runSafe(() => {
Beans.get(MessageClient).publish(PlatformTopics.heartbeat(brokerInfo.clientId)).then();
}));
}
Example #22
Source File: update-dialog.component..ts From App with MIT License | 6 votes |
constructor(dialogRef: MatDialogRef<UpdateDialogComponent>) {
interval(1e3).pipe(
take(AUTO_UPDATE_SECONDS),
switchMap(() => this.autoSeconds.pipe(take(1))),
tap(n => this.autoSeconds.next(n - 1))
).subscribe({
complete: () => {
dialogRef.close(true);
}
});
}
Example #23
Source File: index.ts From FIDO2Client with MIT License | 6 votes |
/**
* Start native card service.
*/
start(): void {
interval(NativeCardServiceUpdateInterval).pipe(takeUntil(this.statusSubject)).subscribe(() => {
try {
this.service.update();
} catch (e) {
this.serviceSubject.error(e);
}
});
}
Example #24
Source File: api.service.ts From blockcore-hub with MIT License | 6 votes |
getNodeStatusCustomInterval(milliseconds: number): Observable<any> {
const self = this;
return interval(milliseconds)
.pipe(startWith(0))
.pipe(switchMap(() => this.http.get(self.apiUrl + '/node/status', { headers: self.headers })))
.pipe(catchError(this.handleError.bind(this)))
.pipe(map((response: Response) => response));
}
Example #25
Source File: logout.component.ts From bitcoin-s-ts with MIT License | 6 votes |
ngOnInit(): void {
this.time = this.data.time
this.timer = interval(1000).subscribe(_ => {
this.time--
if (this.time <= 0) { // < just in case a non-whole number got in
this.timer.unsubscribe()
// Auto-close
this.dialogRef.close()
}
})
}
Example #26
Source File: dynamic-browser-title.service.ts From nghacks with MIT License | 6 votes |
private check(): void {
if (this._titleChecker$) { return; }
const titleCheckingInterval$ = interval(500);
this._titleChecker$ = titleCheckingInterval$.subscribe(val => {
const title = this.getTitleBySelector();
// selector text rendered on the page, setting to tab title
if (title) {
this.setTabTitle(title);
this._titleChecker$.unsubscribe();
this._titleChecker$ = null;
}
// maximum retries done. Couldn't found text with the selector. Stop checking
if (val === 20) {
if (this._titleChecker$) {
this._titleChecker$.unsubscribe();
this._titleChecker$ = null;
}
}
});
}
Example #27
Source File: logout.component.ts From bitcoin-s-ts with MIT License | 6 votes |
ngOnInit(): void {
this.time = this.data.time
this.timer = interval(1000).subscribe(_ => {
this.time--
if (this.time <= 0) { // < just in case a non-whole number got in
this.timer.unsubscribe()
// Auto-close
this.dialogRef.close()
}
})
}
Example #28
Source File: earning-card-front.component.ts From ngx-admin-dotnet-starter with MIT License | 6 votes |
startReceivingLiveData(currency) {
if (this.intervalSubscription) {
this.intervalSubscription.unsubscribe();
}
this.intervalSubscription = interval(200)
.pipe(
takeWhile(() => this.alive),
switchMap(() => this.earningService.getEarningLiveUpdateCardData(currency)),
)
.subscribe((liveUpdateChartData: any[]) => {
this.liveUpdateChartData = [...liveUpdateChartData];
});
}
Example #29
Source File: TodoListEventsController.ts From remix-hexagonal-architecture with MIT License | 6 votes |
@Sse("/:todoListId")
async getEvents(@Param("todoListId") todoListId: string) {
const currentUser = await this.authenticator.currentUser();
const heartbeat$ = interval(30_000).pipe(
map(() => ({ type: "heartbeat", data: "_" }))
);
const updates$ = this.todoListEvents.events.pipe(
filter(
(event) =>
event.todoListId === todoListId &&
event.sessionId !== currentUser.sessionId
),
map((event) => ({ type: "update", data: event.type } as MessageEvent))
);
return merge(heartbeat$, updates$);
}