reuse the context.Context instead of creating a new Context

This commit is contained in:
Steve Zhang 2022-11-28 22:30:09 -07:00
parent cf62eac8f9
commit ccb11cf45e
1 changed files with 2 additions and 3 deletions

View File

@ -35,7 +35,7 @@ func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) {
return nil, err return nil, err
} }
result.Total = cap result.Total = cap
freemem, err := globalZoneFreeMemory() freemem, err := globalZoneFreeMemory(ctx)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -93,8 +93,7 @@ func globalZoneMemoryCapacity() (uint64, error) {
return totalMB * 1024 * 1024, nil return totalMB * 1024 * 1024, nil
} }
func globalZoneFreeMemory() (uint64, error) { func globalZoneFreeMemory(ctx context.Context) (uint64, error) {
ctx := context.Background()
output, err := invoke.CommandWithContext(ctx, "pagesize") output, err := invoke.CommandWithContext(ctx, "pagesize")
if err != nil { if err != nil {
return 0, err return 0, err