263
264
async set(key: string, value: string | boolean | number | null | undefined | object, external = false): Promise<void> {
265
>
if (this.state === StorageState.Closed) {
storage.ts
266
return; // Return early if we are already closed
267
}
269
>
// We remove the key for undefined/null values
270
>
if (isUndefinedOrNull(value)) {
271
return this.delete(key, external);
272
}
274
>
// Otherwise, convert to String and store
275
>
const valueStr = isObject(value) || Array.isArray(value) ? stringify(value) : String(value);
276
>
277
>
// Return early if value already set
278
>
const currentValue = this.cache.get(key);
279
>
if (currentValue === valueStr) {
280
return;
281
}
283
>
// Update in cache and pending
284
>
this.cache.set(key, valueStr);
285
>
this.pendingInserts.set(key, valueStr);
286
>
this.pendingDeletes.delete(key);
287
>
288
>
// Event
289
>
this._onDidChangeStorage.fire({ key, external });
290
>
291
>
// Accumulate work by scheduling after timeout
292
>
return this.doFlush();
293
>
}
294
295
async delete(key: string, external = false): Promise<void> {