|
|
|
|
24
|
import { SpeedyMedia } from 'speedy-vision/types/core/speedy-media';
|
24
|
import { SpeedyMedia } from 'speedy-vision/types/core/speedy-media';
|
25
|
import { SpeedyPromise } from 'speedy-vision/types/core/speedy-promise';
|
25
|
import { SpeedyPromise } from 'speedy-vision/types/core/speedy-promise';
|
26
|
import { ReferenceImage } from './reference-image';
|
26
|
import { ReferenceImage } from './reference-image';
|
|
|
27
|
+import { Utils } from '../../utils/utils';
|
27
|
import { IllegalArgumentError, IllegalOperationError } from '../../utils/errors';
|
28
|
import { IllegalArgumentError, IllegalOperationError } from '../../utils/errors';
|
28
|
|
29
|
|
29
|
/** Default capacity of a Reference Image Database */
|
30
|
/** Default capacity of a Reference Image Database */
|
|
|
|
|
133
|
// handle multiple images as input
|
134
|
// handle multiple images as input
|
134
|
if(referenceImages.length > 1) {
|
135
|
if(referenceImages.length > 1) {
|
135
|
const promises = referenceImages.map(image => this.add([ image ]));
|
136
|
const promises = referenceImages.map(image => this.add([ image ]));
|
136
|
- return Speedy.Promise.all(promises).then(() => void(0));
|
|
|
|
|
137
|
+ return Utils.runInSequence(promises);
|
137
|
}
|
138
|
}
|
138
|
|
139
|
|
139
|
// handle a single image as input
|
140
|
// handle a single image as input
|
|
|
|
|
145
|
|
146
|
|
146
|
// busy loading another image?
|
147
|
// busy loading another image?
|
147
|
if(this._busy)
|
148
|
if(this._busy)
|
148
|
- throw new IllegalOperationError(`Can't add reference image to the database: we're busy loading another image`);
|
|
|
|
|
149
|
+ return Utils.wait(4).then(() => this.add(referenceImages)); // try again later
|
149
|
|
150
|
|
150
|
// reached full capacity?
|
151
|
// reached full capacity?
|
151
|
if(this.count >= this.capacity)
|
152
|
if(this.count >= this.capacity)
|