How do I make a loading provider even works when some background work is going on?

Hi there
I am simply confused about how to use a loading service when some background work is going on.
For example if I push to stack some specific page how do I make a loader that shows till page is ready to be viewed.
Another example I have a LoginAuthenticator provider just yet a fake one which after 3 seconds sends true and in my login page component I show a loader for 3 seconds because I know LoginAuthenticator will send a response in exactly 3 seconds. How do I stop this hard coding and make some provider that takes as input some function and shows a loader till the work is done.
Sorry I am new so please ask if I made some confusion.
Thanks in advance.