github.com/searKing/golang/go@v1.2.117/sync/lock.go (about)

     1  // Copyright 2021 The searKing Author. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package sync
     6  
     7  import "sync"
     8  
     9  // WithLock runs while holding lk.
    10  func WithLock(lk sync.Locker, fn func()) {
    11  	lk.Lock()
    12  	defer lk.Unlock() // in case fn panics
    13  	fn()
    14  }