File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -84,10 +84,11 @@ export class MemoryStore implements LockStore {
8484 async delete ( key : string , owner : string ) {
8585 const mutex = this . #locks. get ( key )
8686
87- if ( ! mutex || ! mutex . releaser ) throw new E_LOCK_NOT_OWNED ( )
87+ if ( ! mutex || ! mutex . releaser ) return
8888 if ( mutex . owner !== owner ) throw new E_LOCK_NOT_OWNED ( )
8989
9090 mutex . releaser ( )
91+ this . #locks. delete ( key )
9192 }
9293
9394 /**
Original file line number Diff line number Diff line change @@ -149,6 +149,28 @@ export function registerStoreTestSuite(options: {
149149 assert . deepEqual ( result , '42' )
150150 } )
151151
152+ test ( 'run is exclusive with two factories' , async ( { assert } ) => {
153+ const provider = new LockFactory ( options . createStore ( ) )
154+ const lock1 = provider . createLock ( 'foo' )
155+ const lock2 = provider . createLock ( 'foo' )
156+
157+ let flag = false
158+ lock1 . run ( async ( ) => {
159+ await sleep ( 500 )
160+ flag = true
161+ } )
162+
163+ assert . isFalse ( flag )
164+
165+ const [ , result ] = await lock2 . run ( async ( ) => {
166+ assert . isTrue ( flag )
167+ return '42'
168+ } )
169+
170+ assert . isTrue ( flag )
171+ assert . deepEqual ( result , '42' )
172+ } )
173+
152174 test ( 'exceptions during run do not leave mutex in locked state' , async ( { assert } ) => {
153175 const provider = new LockFactory ( options . createStore ( ) )
154176 const lock = provider . createLock ( 'foo' )
You can’t perform that action at this time.
0 commit comments