Skip to content

Commit

Permalink
fix: locking closure memory
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwynr committed Aug 9, 2024
1 parent bcaf5b0 commit dcad415
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@filen/sdk",
"version": "0.1.143",
"version": "0.1.144",
"description": "Filen SDK",
"main": "dist/node/index.js",
"browser": "dist/browser/index.js",
Expand Down
16 changes: 6 additions & 10 deletions src/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,11 +599,7 @@ export class User {
}): Promise<void> {
let tries = 0

const acquire = async (): Promise<void> => {
if (tries >= maxTries) {
throw new Error(`Could not acquire lock for resource ${resource}. Max tries of ${maxTries} reached.`)
}

while (tries < maxTries) {
tries += 1

const response = await this.api.v3().user().lock({
Expand All @@ -612,14 +608,14 @@ export class User {
type: "acquire"
})

if (!response.acquired) {
await new Promise<void>(resolve => setTimeout(resolve, tryTimeout))

return await acquire()
if (response.acquired) {
return
}

await new Promise<void>(resolve => setTimeout(resolve, tryTimeout))
}

return await acquire()
throw new Error(`Could not acquire lock for resource ${resource}. Max tries of ${maxTries} reached.`)
}

/**
Expand Down

0 comments on commit dcad415

Please sign in to comment.