Comparing version 4.0.1 to 4.0.2
import { rename, writeFile } from 'node:fs/promises'; | ||
import { basename, dirname, join } from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
import retry from 'async-retry'; | ||
// Returns a temporary file | ||
@@ -11,2 +10,18 @@ // Example: for /some/file will return /some/.file.tmp | ||
} | ||
// Retries an asynchronous operation with a delay between retries and a maximum retry count | ||
async function retryAsyncOperation(fn, maxRetries, delayMs) { | ||
for (let i = 0; i < maxRetries; i++) { | ||
try { | ||
return await fn(); | ||
} | ||
catch (error) { | ||
if (i < maxRetries - 1) { | ||
await new Promise((resolve) => setTimeout(resolve, delayMs)); | ||
} | ||
else { | ||
throw error; // Rethrow the error if max retries reached | ||
} | ||
} | ||
} | ||
} | ||
export class Writer { | ||
@@ -40,7 +55,5 @@ #filename; | ||
await writeFile(this.#tempFilename, data, 'utf-8'); | ||
await retry(async () => { | ||
await retryAsyncOperation(async () => { | ||
await rename(this.#tempFilename, this.#filename); | ||
}, { | ||
minTimeout: 100, | ||
}); | ||
}, 10, 100); | ||
// Call resolve | ||
@@ -47,0 +60,0 @@ this.#prev?.[0](); |
{ | ||
"name": "steno", | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"description": "Specialized fast async file writer", | ||
@@ -61,6 +61,3 @@ "keywords": [ | ||
"node": ">=18" | ||
}, | ||
"dependencies": { | ||
"async-retry": "^1.3.3" | ||
} | ||
} |
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
7082
0
97
- Removedasync-retry@^1.3.3
- Removedasync-retry@1.3.3(transitive)
- Removedretry@0.13.1(transitive)