fix(disposable/deduped): race condition when disposed during acquisition
Introduced in 43aad3d11
This commit is contained in:
@@ -29,7 +29,6 @@ exports.deduped = (factory, keyFn = (...args) => args) =>
|
||||
}
|
||||
|
||||
return () => {
|
||||
++state.users
|
||||
return wrapper
|
||||
}
|
||||
}
|
||||
@@ -47,6 +46,7 @@ exports.deduped = (factory, keyFn = (...args) => args) =>
|
||||
states.set(keys, state)
|
||||
}
|
||||
|
||||
++state.users
|
||||
return state.factory()
|
||||
}
|
||||
})()
|
||||
|
||||
@@ -60,4 +60,17 @@ describe('deduped()', () => {
|
||||
|
||||
expect(dispose).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('no race condition on dispose before async acquisition', async () => {
|
||||
const dispose = jest.fn()
|
||||
const dedupedGetResource = deduped(async () => ({ value: 42, dispose }))
|
||||
|
||||
const d1 = await dedupedGetResource()
|
||||
|
||||
dedupedGetResource()
|
||||
|
||||
d1.dispose()
|
||||
|
||||
expect(dispose).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user