Browse Source

Add a busy flag to the database of reference images

customisations
alemart 1 year ago
parent
commit
e21b4d69b1
1 changed files with 13 additions and 0 deletions
  1. 13
    0
      src/trackers/image-tracker/reference-image-database.ts

+ 13
- 0
src/trackers/image-tracker/reference-image-database.ts View File

61
     /** Is the database locked? */
61
     /** Is the database locked? */
62
     private _locked: boolean;
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
         this._capacity = DEFAULT_CAPACITY;
74
         this._capacity = DEFAULT_CAPACITY;
72
         this._database = [];
75
         this._database = [];
73
         this._locked = false;
76
         this._locked = false;
77
+        this._busy = false;
74
     }
78
     }
75
 
79
 
76
     /**
80
     /**
139
         if(this._locked)
143
         if(this._locked)
140
             throw new IllegalOperationError(`Can't add reference image to the database: it's locked`);
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
         // reached full capacity?
150
         // reached full capacity?
143
         if(this.count >= this.capacity)
151
         if(this.count >= this.capacity)
144
             throw new IllegalOperationError(`Can't add reference image to the database: the capacity of ${this.capacity} images has been exceeded.`);
152
             throw new IllegalOperationError(`Can't add reference image to the database: the capacity of ${this.capacity} images has been exceeded.`);
148
             throw new IllegalArgumentError(`Can't add reference image to the database: found duplicated name "${referenceImage.name}"`);
156
             throw new IllegalArgumentError(`Can't add reference image to the database: found duplicated name "${referenceImage.name}"`);
149
 
157
 
150
         // load the media and add the reference image to the database
158
         // load the media and add the reference image to the database
159
+        this._busy = true;
151
         return Speedy.load(referenceImage.image).then(media => {
160
         return Speedy.load(referenceImage.image).then(media => {
161
+            this._busy = false;
152
             this._database.push({
162
             this._database.push({
153
                 referenceImage: Object.freeze({
163
                 referenceImage: Object.freeze({
154
                     ...referenceImage,
164
                     ...referenceImage,
165
      */
175
      */
166
     _lock(): void
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
         this._locked = true;
181
         this._locked = true;
169
     }
182
     }
170
 
183
 

Loading…
Cancel
Save