Skip to content

Commit

Permalink
Allow to close FsSet instance while locked
Browse files Browse the repository at this point in the history
  • Loading branch information
piranna committed Nov 19, 2023
1 parent 6da8151 commit 8992c26
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 12 additions & 0 deletions __tests__/waiting.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,15 @@ test('lifecycle', async function()

expect(result).toBe(false)
})

test('close while locked', async function()
{
const set = new FsSetWaiting(temporaryFile())

const promise = set.lock(function()
{
set.close()
})

await expect(promise).resolves.toBeUndefined()
})
3 changes: 2 additions & 1 deletion waiting.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export default class FsSetWaiting extends FsSetAbstract
}
finally
{
if(!--this.#locks) await promisedFcntl(this._fd, F_SETLKW, F_UNLCK)
if(!(--this.#locks || this.closed))
await promisedFcntl(this._fd, F_SETLKW, F_UNLCK)
}
}

Expand Down

0 comments on commit 8992c26

Please sign in to comment.