@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.js CHANGED
@@ -441,22 +441,30 @@ function trace(...args) {
441
441
  if (debugTrace) console.log('[OPFS-T2]', ...args);
442
442
  }
443
443
 
444
- // Minimal timer for legacy mode only
444
+ // Handle release timing
445
+ // - Legacy mode (readwrite): 100ms delay (handles block, release ASAP)
446
+ // - Unsafe mode (readwrite-unsafe): 500ms delay (handles don't block each other,
447
+ // but DO block external tools using default mode like OPFS Explorer)
445
448
  let releaseTimer = null;
446
449
  const LEGACY_RELEASE_DELAY = 100;
450
+ const UNSAFE_RELEASE_DELAY = 500;
447
451
 
448
452
  function scheduleHandleRelease() {
449
- if (unsafeModeSupported) return; // No release needed for readwrite-unsafe
450
453
  if (releaseTimer) return; // Already scheduled
454
+
455
+ const delay = unsafeModeSupported ? UNSAFE_RELEASE_DELAY : LEGACY_RELEASE_DELAY;
456
+
451
457
  releaseTimer = setTimeout(() => {
452
458
  releaseTimer = null;
453
459
  const count = syncHandleCache.size;
460
+ if (count === 0) return;
461
+
454
462
  for (const h of syncHandleCache.values()) {
455
463
  try { h.flush(); h.close(); } catch {}
456
464
  }
457
465
  syncHandleCache.clear();
458
- trace('Released ' + count + ' handles (legacy mode debounce)');
459
- }, LEGACY_RELEASE_DELAY);
466
+ trace('Released ' + count + ' handles (' + (unsafeModeSupported ? 'unsafe' : 'legacy') + ' mode, ' + delay + 'ms delay)');
467
+ }, delay);
460
468
  }
461
469
 
462
470
  async function getSyncHandle(filePath, create) {
@@ -942,18 +950,19 @@ async function handleMessage(msg) {
942
950
  function processQueue() {
943
951
  while (messageQueue.length > 0) {
944
952
  const msg = messageQueue.shift();
945
- handleMessage(msg);
953
+ handleMessage(msg); // Process concurrently - don't wait
946
954
  }
947
955
  }
948
956
 
949
- // Handle messages directly - no serialization needed because:
950
- // - Tier 2: Client awaits response before sending next message
951
- // - Each OPFSFileSystem instance has its own worker
957
+ // Handle messages concurrently - each operation proceeds independently
958
+ // This is better than a queue with concurrency limit because:
959
+ // 1. If one operation hangs, others can still complete
960
+ // 2. Small files don't get blocked behind large files
961
+ // 3. The Web Locks API already handles per-file serialization
952
962
  self.onmessage = (event) => {
963
+ messageQueue.push(event.data);
953
964
  if (isReady) {
954
- handleMessage(event.data);
955
- } else {
956
- messageQueue.push(event.data);
965
+ processQueue();
957
966
  }
958
967
  };
959
968