File tree Expand file tree Collapse file tree 1 file changed +22
-6
lines changed
Expand file tree Collapse file tree 1 file changed +22
-6
lines changed Original file line number Diff line number Diff line change 6363 }
6464
6565 async function getAuthorization ( key , organization_id ) {
66- if ( authorizations . get ( key ) ) {
67- return authorizations . get ( key )
68- } else {
69- let authorization = await readAuthorization ( key , organization_id ) ;
70- authorizations . set ( key , authorization )
71- return authorization
66+ // Check if there is a value orpending promise for this key
67+ if ( authorizations . has ( key ) ) {
68+ // Return the value or pending promise
69+ return authorizations . get ( key ) ;
70+ }
71+
72+ // Create a new promise and store it
73+ const authorizationPromise = readAuthorization ( key , organization_id ) ;
74+ authorizations . set ( key , authorizationPromise ) ;
75+
76+ try {
77+ // Wait for the authorization to be resolved
78+ const authorization = await authorizationPromise ;
79+
80+ // Once resolved, store the resolved authorization in the map
81+ authorizations . set ( key , authorization ) ;
82+
83+ return authorization ;
84+ } catch ( error ) {
85+ // Handle errors if necessary
86+ authorizations . delete ( key ) ;
87+ throw error ;
7288 }
7389 }
7490
You can’t perform that action at this time.
0 commit comments