[lib] Cancel an auth every time dependencies change
Summary:
Extract a callback from the effect. This callback returns a promise and a function that can cancel it.
Cancelling a promise is implemented by checking the flag and throwing an exception if a flag is true.
The effect depends on a callback and on canPerformAuth flag, which handles a retries delay. When the callback changes, it means that some of its deps changed and we should start a new auth. The first operation in the callback is to set canPerformAuth to false, which then would result in the effect being fired, but the callback itself doesn't depend on this flag. That allows us to easily check if we need to cancel just by comparing the callback with its previous value.
Depends on D10844
Test Plan: Comment out checking usingCommServicesAccessToken and isUserAuthenticated flags. Added a lot of console logs and some sleeps to make sure that canceling an ongoing auth results in throwing an exception and restarts an auth.
Reviewers: varun, inka, kamil, ashoat
Reviewed By: ashoat
Subscribers: ashoat
Differential Revision: https://phab.comm.dev/D10884