blob: 6f1b128589bde634cce287f25694c9f3fe9fe003 [file] [log] [blame]
Dan Willemsenbc60c3c2021-12-15 01:09:00 -08001// Copyright 2021 The Go Authors. 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
5package a
6
7import (
8 "fmt"
9 "sync"
10)
11
12type WrapperWithLock[T any] interface {
13 PrintWithLock()
14}
15
16func NewWrapperWithLock[T any](value T) WrapperWithLock[T] {
17 return &wrapperWithLock[T]{
18 Object: value,
19 }
20}
21
22type wrapperWithLock[T any] struct {
23 Lock sync.Mutex
24 Object T
25}
26
27func (w *wrapperWithLock[T]) PrintWithLock() {
28 w.Lock.Lock()
29 defer w.Lock.Unlock()
30
31 fmt.Println(w.Object)
32}