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

feat(std): add std/node/os/totalmem, freemem #8317

Merged
merged 4 commits into from Nov 19, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions std/node/_os.ts
Expand Up @@ -123,9 +123,9 @@ export function endianness(): "BE" | "LE" {
return new Int16Array(buffer)[0] === 256 ? "LE" : "BE";
}

/** Not yet implemented */
/** Return free memory amount */
export function freemem(): number {
notImplemented(SEE_GITHUB_ISSUE);
return Deno.systemMemoryInfo().free;
}

/** Not yet implemented */
Expand Down Expand Up @@ -185,9 +185,9 @@ export function tmpdir(): string | null {
notImplemented(SEE_GITHUB_ISSUE);
}

/** Not yet implemented */
/** Return total physical memory amount */
export function totalmem(): number {
notImplemented(SEE_GITHUB_ISSUE);
return Deno.systemMemoryInfo().total;
}

/** Not yet implemented */
Expand Down
28 changes: 14 additions & 14 deletions std/node/os_test.ts
Expand Up @@ -200,6 +200,20 @@ Deno.test({
},
});

Deno.test({
name: "Total memory amount should be greater than 0",
fn() {
assert(os.totalmem() > 0);
},
});

Deno.test({
name: "Free memory amount should be greater than 0",
fn() {
assert(os.freemem() > 0);
},
});

Deno.test({
name: "APIs not yet implemented",
fn() {
Expand All @@ -210,13 +224,6 @@ Deno.test({
Error,
"Not implemented",
);
assertThrows(
() => {
os.freemem();
},
Error,
"Not implemented",
);
assertThrows(
() => {
os.getPriority();
Expand All @@ -238,13 +245,6 @@ Deno.test({
Error,
"Not implemented",
);
assertThrows(
() => {
os.totalmem();
},
Error,
"Not implemented",
);
assertThrows(
() => {
os.type();
Expand Down