Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function fetchSubscription() {
- return new Promise((resolve) => {
- resolve("pro_tier");
- });
- }
- var subscriptionPromise = [];
- async function getSubscription() {
- if (subscriptionPromise.length === 0) {
- subscriptionPromise.push(
- new Promise(async (resolve) => {
- const freshness = await getLocalStorage("rpSubscriptionFreshness");
- if (!freshness || Date.now() >= freshness + 300 * 1000) {
- try {
- await validateUser();
- const subscription = await fetchSubscription();
- setLocalStorage("rpSubscription", subscription);
- setLocalStorage("rpSubscriptionFreshness", Date.now());
- resolve(subscription);
- } catch (e) {
- console.log("Error fetching subscription: ", e);
- setLocalStorage("rpSubscriptionFreshness", Date.now());
- }
- } else {
- resolve(await getLocalStorage("rpSubscription"));
- }
- })
- );
- }
- const myPromise = await subscriptionPromise[0];
- subscriptionPromise = [];
- return myPromise;
- }
- getSubscription();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement