mirror of
https://github.com/shirou/gopsutil.git
synced 2025-04-26 13:48:59 +08:00
close channel in function that sends to it
This commit is contained in:
parent
c7c548d6bd
commit
3a88ef27a5
@ -7,6 +7,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
@ -90,12 +91,20 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
|
|||||||
var ret []PartitionStat
|
var ret []PartitionStat
|
||||||
retChan := make(chan []PartitionStat)
|
retChan := make(chan []PartitionStat)
|
||||||
errChan := make(chan error)
|
errChan := make(chan error)
|
||||||
defer close(retChan)
|
|
||||||
defer close(errChan)
|
|
||||||
|
|
||||||
lpBuffer := make([]byte, 254)
|
lpBuffer := make([]byte, 254)
|
||||||
|
|
||||||
|
var waitgrp sync.WaitGroup
|
||||||
|
waitgrp.Add(1)
|
||||||
|
defer waitgrp.Done()
|
||||||
|
|
||||||
f := func() {
|
f := func() {
|
||||||
|
defer func() {
|
||||||
|
waitgrp.Wait()
|
||||||
|
// fires when this func and the outside func finishes.
|
||||||
|
close(errChan)
|
||||||
|
close(retChan)
|
||||||
|
}()
|
||||||
|
|
||||||
diskret, _, err := procGetLogicalDriveStringsW.Call(
|
diskret, _, err := procGetLogicalDriveStringsW.Call(
|
||||||
uintptr(len(lpBuffer)),
|
uintptr(len(lpBuffer)),
|
||||||
uintptr(unsafe.Pointer(&lpBuffer[0])))
|
uintptr(unsafe.Pointer(&lpBuffer[0])))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user