async function beginRefresh(getAccessToken, retryIntervalInMs, refreshTimeout) {
    // This wrapper handles exceptions gracefully as long as we haven't exceeded
    // the timeout.
    async function tryGetAccessToken() {
        if (Date.now() < refreshTimeout) {
            try {
                return await getAccessToken();
            }
            catch (_a) {
                return null;
            }
        }
        else {
            const finalToken = await getAccessToken();
            // Timeout is up, so throw if it's still null
            if (finalToken === null) {
                throw new Error("Failed to refresh access token.");
            }
            return finalToken;
        }
    }
    let token = await tryGetAccessToken();
    while (token === null) {
        await (0, core_util_1.delay)(retryIntervalInMs);
        token = await tryGetAccessToken();
    }
    return token;
}
Converts an an unreliable access token getter (which may resolve with null)
into an AccessTokenGetter by retrying the unreliable getter in a regular
interval.

@param getAccessToken - A function that produces a promise of an access token that may fail by returning null.
@param retryIntervalInMs - The time (in milliseconds) to wait between retry attempts.
@param refreshTimeout - The timestamp after which the refresh attempt will fail, throwing an exception.
@returns - A promise that, if it resolves, will resolve with an access token.