generated from blockmatic-icebox/powerstack
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
960c390
commit 1e68b30
Showing
3 changed files
with
82 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
import fs from 'fs/promises' | ||
|
||
export async function writeToFile(data:string, filePath:string) { | ||
export async function writeToFile(data: string, filePath: string) { | ||
try { | ||
// Write the data to the specified file | ||
// If the file does not exist, it will be created. | ||
await fs.writeFile(filePath, data, 'utf8'); | ||
console.log('Logs have been written to the file successfully.'); | ||
await fs.writeFile(filePath, data, 'utf8') | ||
|
||
console.log('Logs have been written to the file successfully.') | ||
} catch (error) { | ||
console.error('Error writing logs to file:', error); | ||
console.error('Error writing logs to file:', error) | ||
} | ||
} | ||
} | ||
|
||
export function runPromisesInSeries<T>(promiseFns: (() => Promise<T>)[]): Promise<T | void> { | ||
// Start with a Promise<void> to ensure compatibility with the accumulator's type | ||
return promiseFns.reduce<Promise<T | void>>((prevPromise, currentPromiseFn) => { | ||
// Chain the current promise to the accumulator after the previous one completes | ||
// Here, we ignore the result of the previous promise, as we're focusing on chaining | ||
// If collecting results is needed, an additional structure would be required | ||
return prevPromise.then(() => currentPromiseFn()) | ||
}, Promise.resolve()) | ||
} |