control/controlclient,util/execqueue: extract execqueue into a package

This is a useful primitive for asynchronous execution of ordered work I
want to use in another change.

Updates tailscale/corp#16833
Signed-off-by: James Tucker <[email protected]>
(cherry picked from commit 38a1cf748a)
This commit is contained in:
James Tucker authored and kari-ts committed 2024-01-23 10:14:58 -08:00
1 parent dfc5715d94
commit 36e3c418aa
4 files changed
+131 -95

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
package execqueue
import (
"context"
"sync/atomic"
"testing"
)
func TestExecQueue(t *testing.T) {
ctx := context.Background()
var n atomic.Int32
q := &ExecQueue{}
defer q.Shutdown()
q.Add(func() { n.Add(1) })
q.Wait(ctx)
if got := n.Load(); got != 1 {
t.Errorf("n=%d; want 1", got)
}
}