mirror of
				https://github.com/tailscale/tailscale.git
				synced 2025-11-04 10:11:18 +01:00 
			
		
		
		
	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 <james@tailscale.com>
		
			
				
	
	
		
			23 lines
		
	
	
		
			384 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			23 lines
		
	
	
		
			384 B
		
	
	
	
		
			Go
		
	
	
	
	
	
// 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)
 | 
						|
	}
 | 
						|
}
 |