2

Let's say we have Angular 5+ app and I would want to run certain "jobs" (like loading more of data from server via API call) during idle times when we are mostly sure the user is not doing anything (as we also control inputs through input events).

Can we use NgZone.hasPendingMicrotasks & NgZone.hasPendingMacrotasts for that?

Practical example:

  • Angular application uses MixPanel to report usage stats
  • Implementation currently buffers data in a form of stack and only sends it to MixPanel API when the stack is full (exceeds certain limit)
  • Ideally it should also meet another criteria (apart from stack being full) - there is no activity at the moment.

I know this might sound as micro optimization and also I guess there are better ways t deal with this (maybe workers), but I would want to learn if there is a way to see how "busy" the app is and potentially leverage idle times for certain tasks.

Sergey Rudenko
  • 8,809
  • 2
  • 24
  • 51

1 Answers1

0

You can use ngZone.onStable and ngZone.onUnstable emitter to do that.

jiali passion
  • 1,691
  • 1
  • 14
  • 19