1import { UnavailabilityError, Platform } from 'expo-modules-core';
2import PushTokenManager from './PushTokenManager';
3let nativeTokenPromise = null;
4/**
5 * Returns a native FCM, APNs token or a [`PushSubscription` data](https://developer.mozilla.org/en-US/docs/Web/API/PushSubscription)
6 * that can be used with another push notification service.
7 * @header fetch
8 */
9export default async function getDevicePushTokenAsync() {
10    if (!PushTokenManager.getDevicePushTokenAsync) {
11        throw new UnavailabilityError('ExpoNotifications', 'getDevicePushTokenAsync');
12    }
13    let devicePushToken;
14    if (nativeTokenPromise) {
15        // Reuse existing Promise
16        devicePushToken = await nativeTokenPromise;
17    }
18    else {
19        // Create a new Promise and clear it afterwards
20        nativeTokenPromise = PushTokenManager.getDevicePushTokenAsync();
21        devicePushToken = await nativeTokenPromise;
22        nativeTokenPromise = null;
23    }
24    // @ts-ignore: TS thinks Platform.OS could be anything and can't decide what type is it
25    return { type: Platform.OS, data: devicePushToken };
26}
27//# sourceMappingURL=getDevicePushTokenAsync.js.map