fix: race condition in declaration-data.js
parent
9af4c720f0
commit
5ce54e8e10
|
@ -25,6 +25,7 @@ export class DeclarationDataCenter {
|
|||
* Used to implement the singleton, in case we need to fetch data mutiple times in the same page.
|
||||
*/
|
||||
static singleton = null;
|
||||
static requestSingleton = null;
|
||||
|
||||
/**
|
||||
* Construct a DeclarationDataCenter with given data.
|
||||
|
@ -41,7 +42,16 @@ export class DeclarationDataCenter {
|
|||
* @returns {Promise<DeclarationDataCenter>}
|
||||
*/
|
||||
static async init() {
|
||||
if (!DeclarationDataCenter.singleton) {
|
||||
if (DeclarationDataCenter.singleton === null) {
|
||||
if (DeclarationDataCenter.requestSingleton === null) {
|
||||
DeclarationDataCenter.requestSingleton = DeclarationDataCenter.getData();
|
||||
}
|
||||
await DeclarationDataCenter.requestSingleton;
|
||||
}
|
||||
return DeclarationDataCenter.singleton;
|
||||
}
|
||||
|
||||
static async getData() {
|
||||
const dataListUrl = new URL(
|
||||
`${SITE_ROOT}/declarations/declaration-data.bmp`,
|
||||
window.location
|
||||
|
@ -60,8 +70,6 @@ export class DeclarationDataCenter {
|
|||
DeclarationDataCenter.singleton = new DeclarationDataCenter(data);
|
||||
}
|
||||
}
|
||||
return DeclarationDataCenter.singleton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for a declaration.
|
||||
|
|
Loading…
Reference in New Issue