Skip to content

Commit

Permalink
fix: the app hang on bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
khmm12 committed Jun 25, 2024
1 parent 0841909 commit 70fd17c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/utils/storage/storage.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import StorageSubscription from './subscription'
import type { ISerializer, IStorage, IStorageAdapter, Subscriber, Unsubscribe } from './types'

type DeferredValue<T> = { value: T; loaded: true } | { loaded: false }

// Extracts subscription to a separate chunk.
// Fixes the issue with circular chunks caused by top-level await.
const { default: Subscription } = await import('./subscription')

export default class Storage<T> implements IStorage<T> {
static async create<T>(adapter: IStorageAdapter, serializer: ISerializer<T>): Promise<Storage<T>> {
const storage = new Storage<T>(adapter, serializer)
Expand All @@ -12,7 +15,8 @@ export default class Storage<T> implements IStorage<T> {

protected readonly adapter: IStorageAdapter
protected readonly serializer: ISerializer<T>
protected readonly subscription = new StorageSubscription<T>()
// eslint-disable-next-line new-cap
protected readonly subscription = new Subscription<T>()

protected currentValue: DeferredValue<T> = { loaded: false }

Expand Down

0 comments on commit 70fd17c

Please sign in to comment.