0

I'm new to Ngrx and am having issues setting up polling with Ngrx effects

I've tried the answer mentioned How to do http polling in ngrx effect but this does not seem to be working as expected for my solution. I have a feeling that this could be because of my return statement

 LoadProcessesByUser$: Observable<Action> = this.actions$.pipe(
   ofType(AppActions.LoadProcessesByUser),
   switchMap(() => {
     interval(100).pipe(
       startWith(0),
       mapTo(this.actions$)
     );
     return this.apiService.getUserProcesses(this.userService.user.lanId).pipe(
       map(result => new LoadProcessesSuccess(result)),
       catchError(error => of(new LoadFailure(error)))
     );
   })
 );

I expected to see this effect being called every 100 ms but as it seems, it's only called whenever I dispatch LoadProcessByUser()

Do note; i want this polling to be running for the life of the application.

Thank you

Steven Marrocco
  • 111
  • 1
  • 10

1 Answers1

0

You're not doing anything with the interval, you will have to return the interval and add the service call inside the intervals pipe.

If you don't need LoadProcessesByUser you can also create a stream based on the interval, for example

@Effect() 
ping = interval(1000).pipe(mapTo(new Ping()));

You can find more at Start using ngrx/effects for this

timdeschryver
  • 14,415
  • 1
  • 19
  • 32