mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 21:15:39 +00:00
2bc518dcb2
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
29 lines
714 B
Go
29 lines
714 B
Go
// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package ipnlocal
|
|
|
|
import "sync"
|
|
|
|
// LocalBackendFuture is a Future that returns a *LocalBackend.
|
|
type LocalBackendFuture struct {
|
|
getOnce sync.Once
|
|
ch chan *LocalBackend
|
|
v *LocalBackend
|
|
}
|
|
|
|
func (f *LocalBackendFuture) Get() *LocalBackend {
|
|
f.getOnce.Do(f.get)
|
|
return f.v
|
|
}
|
|
|
|
func (f *LocalBackendFuture) get() { f.v = <-f.ch }
|
|
func (f *LocalBackendFuture) Set(v *LocalBackend) { f.ch <- v }
|
|
|
|
func NewLocalBackendFuture() *LocalBackendFuture {
|
|
return &LocalBackendFuture{
|
|
ch: make(chan *LocalBackend, 1),
|
|
}
|
|
}
|