28 lines
909 B
JavaScript
28 lines
909 B
JavaScript
const sharedAsyncLocalStorageNotAvailableError = new Error("Invariant: AsyncLocalStorage accessed in runtime where it is not available");
|
|
class FakeAsyncLocalStorage {
|
|
disable() {
|
|
throw sharedAsyncLocalStorageNotAvailableError;
|
|
}
|
|
getStore() {
|
|
// This fake implementation of AsyncLocalStorage always returns `undefined`.
|
|
return undefined;
|
|
}
|
|
run() {
|
|
throw sharedAsyncLocalStorageNotAvailableError;
|
|
}
|
|
exit() {
|
|
throw sharedAsyncLocalStorageNotAvailableError;
|
|
}
|
|
enterWith() {
|
|
throw sharedAsyncLocalStorageNotAvailableError;
|
|
}
|
|
}
|
|
const maybeGlobalAsyncLocalStorage = globalThis.AsyncLocalStorage;
|
|
export function createAsyncLocalStorage() {
|
|
if (maybeGlobalAsyncLocalStorage) {
|
|
return new maybeGlobalAsyncLocalStorage();
|
|
}
|
|
return new FakeAsyncLocalStorage();
|
|
}
|
|
|
|
//# sourceMappingURL=async-local-storage.js.map
|