Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use util.promisify instead of manually constructing promise #1184

Merged
merged 1 commit into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions lib/trap-caching.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/trap-caching.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 12 additions & 15 deletions src/trap-caching.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from "fs";
import * as path from "path";
import { promisify } from "util";

import * as cache from "@actions/cache";
import getFolderSize from "get-folder-size";
Expand Down Expand Up @@ -188,21 +189,17 @@ export async function getTotalCacheSize(
trapCaches: Partial<Record<Language, string>>,
logger: Logger
): Promise<number> {
const sizes = await Promise.all(
Object.values(trapCaches).map(async (cacheDir) => {
return new Promise<number>((resolve) => {
getFolderSize(cacheDir, (err, size) => {
if (err) {
logger.warning(`Error getting size of ${cacheDir}: ${err}`);
resolve(0);
} else {
resolve(size);
}
});
});
})
);
return sizes.reduce((a, b) => a + b, 0);
try {
const sizes = await Promise.all(
Object.values(trapCaches).map(async (cacheDir) => {
return promisify<string, number>(getFolderSize)(cacheDir);
})
);
return sizes.reduce((a, b) => a + b, 0);
} catch (e) {
logger.warning(`Encountered an error while getting TRAP cache size: ${e}`);
return 0;
}
}

async function cacheKey(
Expand Down