Skip to content

Instantly share code, notes, and snippets.

@BrianJVarley
Created October 3, 2019 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrianJVarley/8b4f00a843aa615528af296d42d98ad5 to your computer and use it in GitHub Desktop.
Save BrianJVarley/8b4f00a843aa615528af296d42d98ad5 to your computer and use it in GitHub Desktop.
import {
EAppActions,
GetFiles
} from '../actions/app.actions';
import { Injectable } from '@angular/core';
import { Effect, ofType, Actions } from '@ngrx/effects';
import { of } from 'rxjs';
import { switchMap, map, catchError, mergeMap, delay, takeWhile } from 'rxjs/operators';
import { FileService } from 'src/app/utils/FileService';
@Injectable()
export class ResourceEffects {
constructor(
private actions$: Actions,
private fileService: FileService,
) {}
private isPollingActive = false;
@Effect({ dispatch: false })
continuePolling$ = this.actions$.pipe(
ofType<GetFiles>(EAppActions.GetFiles),
takeWhile(() => this.isPollingActive),
switchMap(() => {
this.isPollingActive = true;
return this.fileService
.getResourceFileJs(`http://localhost:5002/myRemoteFile.js`)
.pipe(
delay(5000),
map((response: any) => {
const responseHeaders = response.headers;
}),
);
}),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment