|
@@ -61,6 +61,9 @@ export class ReferenceImageDatabase implements Iterable<ReferenceImage>
|
61
|
61
|
/** Is the database locked? */
|
62
|
62
|
private _locked: boolean;
|
63
|
63
|
|
|
64
|
+ /** Are we busy loading an image? */
|
|
65
|
+ private _busy: boolean;
|
|
66
|
+
|
64
|
67
|
|
65
|
68
|
|
66
|
69
|
/**
|
|
@@ -71,6 +74,7 @@ export class ReferenceImageDatabase implements Iterable<ReferenceImage>
|
71
|
74
|
this._capacity = DEFAULT_CAPACITY;
|
72
|
75
|
this._database = [];
|
73
|
76
|
this._locked = false;
|
|
77
|
+ this._busy = false;
|
74
|
78
|
}
|
75
|
79
|
|
76
|
80
|
/**
|
|
@@ -139,6 +143,10 @@ export class ReferenceImageDatabase implements Iterable<ReferenceImage>
|
139
|
143
|
if(this._locked)
|
140
|
144
|
throw new IllegalOperationError(`Can't add reference image to the database: it's locked`);
|
141
|
145
|
|
|
146
|
+ // busy loading another image?
|
|
147
|
+ if(this._busy)
|
|
148
|
+ throw new IllegalOperationError(`Can't add reference image to the database: we're busy loading another image`);
|
|
149
|
+
|
142
|
150
|
// reached full capacity?
|
143
|
151
|
if(this.count >= this.capacity)
|
144
|
152
|
throw new IllegalOperationError(`Can't add reference image to the database: the capacity of ${this.capacity} images has been exceeded.`);
|
|
@@ -148,7 +156,9 @@ export class ReferenceImageDatabase implements Iterable<ReferenceImage>
|
148
|
156
|
throw new IllegalArgumentError(`Can't add reference image to the database: found duplicated name "${referenceImage.name}"`);
|
149
|
157
|
|
150
|
158
|
// load the media and add the reference image to the database
|
|
159
|
+ this._busy = true;
|
151
|
160
|
return Speedy.load(referenceImage.image).then(media => {
|
|
161
|
+ this._busy = false;
|
152
|
162
|
this._database.push({
|
153
|
163
|
referenceImage: Object.freeze({
|
154
|
164
|
...referenceImage,
|
|
@@ -165,6 +175,9 @@ export class ReferenceImageDatabase implements Iterable<ReferenceImage>
|
165
|
175
|
*/
|
166
|
176
|
_lock(): void
|
167
|
177
|
{
|
|
178
|
+ if(this._busy)
|
|
179
|
+ throw new IllegalOperationError(`Can't lock the reference image database: we're busy loading an image`);
|
|
180
|
+
|
168
|
181
|
this._locked = true;
|
169
|
182
|
}
|
170
|
183
|
|