Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gps
- import (
- "context"
- "sync/atomic"
- )
- func (sm *SourceMgr) ListPackages(ctx context.Context, id ProjectIdentifier, v Version) (PackageTree, error) {
- subctx, cancel := context.WithCancel(ctx)
- quitchan := make(chan struct{})
- go func() {
- select {
- case <-ctx.Done():
- // cancel initiated by the caller
- case <-sm.cm.quitchan:
- // quitchan closed centrally; trigger the cancel func for the subctx
- cancel()
- case <-quitchan:
- // local quitchan was closed
- }
- }
- // do stuff
- // ...
- // close the quitchan to kill the goroutine
- close(quitchan)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement