@jsenv/filesystem
Advanced tools
Comparing version 4.0.10 to 4.1.0
{ | ||
"name": "@jsenv/filesystem", | ||
"version": "4.0.10", | ||
"version": "4.1.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -5,2 +5,21 @@ export const guardTooFastSecondCall = ( | ||
) => { | ||
let previousCallMs | ||
return (...args) => { | ||
const nowMs = Date.now() | ||
if (previousCallMs) { | ||
const msEllapsed = nowMs - previousCallMs | ||
if (msEllapsed < cooldownBetweenFileEvents) { | ||
previousCallMs = null | ||
return | ||
} | ||
} | ||
previousCallMs = nowMs | ||
callback(...args) | ||
} | ||
} | ||
export const guardTooFastSecondCallPerFile = ( | ||
callback, | ||
cooldownBetweenFileEvents = 40, | ||
) => { | ||
const previousCallMsMap = new Map() | ||
@@ -7,0 +26,0 @@ return (fileEvent) => { |
@@ -7,3 +7,3 @@ import { readdirSync, statSync } from "node:fs" | ||
import { statsToType } from "./internal/statsToType.js" | ||
import { guardTooFastSecondCall } from "./internal/guard_second_call.js" | ||
import { guardTooFastSecondCallPerFile } from "./internal/guard_second_call.js" | ||
import { createWatcher } from "./internal/createWatcher.js" | ||
@@ -53,9 +53,15 @@ import { trackRessources } from "./internal/trackRessources.js" | ||
if (added) { | ||
added = guardTooFastSecondCall(added, cooldownBetweenFileEvents) | ||
added = guardTooFastSecondCallPerFile(added, cooldownBetweenFileEvents) | ||
} | ||
if (updated) { | ||
updated = guardTooFastSecondCall(updated, cooldownBetweenFileEvents) | ||
updated = guardTooFastSecondCallPerFile( | ||
updated, | ||
cooldownBetweenFileEvents, | ||
) | ||
} | ||
if (removed) { | ||
removed = guardTooFastSecondCall(removed, cooldownBetweenFileEvents) | ||
removed = guardTooFastSecondCallPerFile( | ||
removed, | ||
cooldownBetweenFileEvents, | ||
) | ||
} | ||
@@ -62,0 +68,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
87090
2567