@supabase/gotrue-js 2.46.2 → 2.47.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/lib/locks.ts CHANGED
@@ -59,106 +59,50 @@ export async function navigatorLock<R>(
59
59
  console.log('@supabase/gotrue-js: navigatorLock: acquire lock', name, acquireTimeout)
60
60
  }
61
61
 
62
- let beginOperation: (() => void) | null = null
63
- let rejectOperation: ((error: any) => void) | null = null
64
- const beginOperationPromise = new Promise<void>((accept, reject) => {
65
- beginOperation = accept
66
- rejectOperation = reject
67
- })
68
-
69
- // this lets us preserve stack traces over the operation, which the
70
- // navigator.locks.request function does not preserve well still
71
- const result = (async () => {
72
- await beginOperationPromise
73
-
74
- if (internals.debug) {
75
- console.log('@supabase/gotrue-js: navigatorLock: operation start')
76
- }
77
-
78
- try {
79
- return await fn()
80
- } finally {
81
- if (internals.debug) {
82
- console.log('@supabase/gotrue-js: navigatorLock: operation end')
83
- }
84
- }
85
- })()
86
-
87
62
  const abortController = new globalThis.AbortController()
88
63
 
89
64
  if (acquireTimeout > 0) {
90
65
  setTimeout(() => {
91
- beginOperation = null
92
66
  abortController.abort()
93
-
94
- if (rejectOperation) {
95
- if (internals.debug) {
96
- console.log('@supabase/gotrue-js: navigatorLock acquire timed out', name)
97
- }
98
-
99
- if (rejectOperation) {
100
- rejectOperation(
101
- new NavigatorLockAcquireTimeoutError(
102
- `Acquiring an exclusive Navigator LockManager lock "${name}" timed out after ${acquireTimeout}ms`
103
- )
104
- )
105
- }
106
- beginOperation = null
107
- rejectOperation = null
67
+ if (internals.debug) {
68
+ console.log('@supabase/gotrue-js: navigatorLock acquire timed out', name)
108
69
  }
109
70
  }, acquireTimeout)
110
71
  }
111
72
 
112
- await globalThis.navigator.locks.request(
73
+ return await globalThis.navigator.locks.request(
113
74
  name,
114
- {
115
- mode: 'exclusive',
116
- ifAvailable: acquireTimeout === 0,
117
- signal: abortController.signal,
118
- },
75
+ acquireTimeout === 0
76
+ ? {
77
+ mode: 'exclusive',
78
+ ifAvailable: true,
79
+ }
80
+ : {
81
+ mode: 'exclusive',
82
+ signal: abortController.signal,
83
+ },
119
84
  async (lock) => {
120
85
  if (lock) {
121
86
  if (internals.debug) {
122
- console.log('@supabase/gotrue-js: navigatorLock acquired', name)
87
+ console.log('@supabase/gotrue-js: navigatorLock: acquired', name)
123
88
  }
124
89
 
125
90
  try {
126
- if (beginOperation) {
127
- beginOperation()
128
- beginOperation = null
129
- rejectOperation = null
130
- await result
131
- }
132
- } catch (e: any) {
133
- // not important to handle the error here
91
+ return await fn()
134
92
  } finally {
135
93
  if (internals.debug) {
136
- console.log('@supabase/gotrue-js: navigatorLock released', name)
94
+ console.log('@supabase/gotrue-js: navigatorLock: released', name)
137
95
  }
138
96
  }
139
97
  } else {
140
98
  if (internals.debug) {
141
- console.log('@supabase/gotrue-js: navigatorLock not immediately available', name)
99
+ console.log('@supabase/gotrue-js: navigatorLock: not immediately available', name)
142
100
  }
143
101
 
144
- // no lock was available because acquireTimeout === 0
145
- const timeout: any = new Error(
102
+ throw new NavigatorLockAcquireTimeoutError(
146
103
  `Acquiring an exclusive Navigator LockManager lock "${name}" immediately failed`
147
104
  )
148
- timeout.isAcquireTimeout = true
149
-
150
- if (rejectOperation) {
151
- rejectOperation(
152
- new NavigatorLockAcquireTimeoutError(
153
- `Acquiring an exclusive Navigator LockManager lock "${name}" immediately failed`
154
- )
155
- )
156
- }
157
- beginOperation = null
158
- rejectOperation = null
159
105
  }
160
106
  }
161
107
  )
162
-
163
- return await result
164
108
  }
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '2.46.2'
2
+ export const version = '2.47.0'