@componentor/fs 2.0.8 → 2.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -445,22 +445,30 @@ function trace(...args) {
445
445
  if (debugTrace) console.log('[OPFS-T2]', ...args);
446
446
  }
447
447
 
448
- // Minimal timer for legacy mode only
448
+ // Handle release timing
449
+ // - Legacy mode (readwrite): 100ms delay (handles block, release ASAP)
450
+ // - Unsafe mode (readwrite-unsafe): 500ms delay (handles don't block each other,
451
+ // but DO block external tools using default mode like OPFS Explorer)
449
452
  let releaseTimer = null;
450
453
  const LEGACY_RELEASE_DELAY = 100;
454
+ const UNSAFE_RELEASE_DELAY = 500;
451
455
 
452
456
  function scheduleHandleRelease() {
453
- if (unsafeModeSupported) return; // No release needed for readwrite-unsafe
454
457
  if (releaseTimer) return; // Already scheduled
458
+
459
+ const delay = unsafeModeSupported ? UNSAFE_RELEASE_DELAY : LEGACY_RELEASE_DELAY;
460
+
455
461
  releaseTimer = setTimeout(() => {
456
462
  releaseTimer = null;
457
463
  const count = syncHandleCache.size;
464
+ if (count === 0) return;
465
+
458
466
  for (const h of syncHandleCache.values()) {
459
467
  try { h.flush(); h.close(); } catch {}
460
468
  }
461
469
  syncHandleCache.clear();
462
- trace('Released ' + count + ' handles (legacy mode debounce)');
463
- }, LEGACY_RELEASE_DELAY);
470
+ trace('Released ' + count + ' handles (' + (unsafeModeSupported ? 'unsafe' : 'legacy') + ' mode, ' + delay + 'ms delay)');
471
+ }, delay);
464
472
  }
465
473
 
466
474
  async function getSyncHandle(filePath, create) {
@@ -946,18 +954,19 @@ async function handleMessage(msg) {
946
954
  function processQueue() {
947
955
  while (messageQueue.length > 0) {
948
956
  const msg = messageQueue.shift();
949
- handleMessage(msg);
957
+ handleMessage(msg); // Process concurrently - don't wait
950
958
  }
951
959
  }
952
960
 
953
- // Handle messages directly - no serialization needed because:
954
- // - Tier 2: Client awaits response before sending next message
955
- // - Each OPFSFileSystem instance has its own worker
961
+ // Handle messages concurrently - each operation proceeds independently
962
+ // This is better than a queue with concurrency limit because:
963
+ // 1. If one operation hangs, others can still complete
964
+ // 2. Small files don't get blocked behind large files
965
+ // 3. The Web Locks API already handles per-file serialization
956
966
  self.onmessage = (event) => {
967
+ messageQueue.push(event.data);
957
968
  if (isReady) {
958
- handleMessage(event.data);
959
- } else {
960
- messageQueue.push(event.data);
969
+ processQueue();
961
970
  }
962
971
  };
963
972