code: func (a *Allocator) Run(ctx context.Context) error {
  	// Setup cancel context for all goroutines to use.
  	ctx, cancel := context.WithCancel(ctx)
  	var (
  		wg     sync.WaitGroup
  		actors []func() error
  	)
  
  	defer func() {
  		cancel()
  		wg.Wait()
  		close(a.doneChan)
  	}()
  
  	for _, aa := range []allocActor{
  		{
  			taskVoter: networkVoter,
  			init:      a.doNetworkInit,
  			action:    a.doNetworkAlloc,
  		},
  	} {
  		if aa.taskVoter != "" {
  			a.registerToVote(aa.taskVoter)
  		}
  
  		// Assign a pointer for variable capture
  		aaPtr := &aa
  		actor := func() error {
  			wg.Add(1)
  			defer wg.Done()
  
  			// init might return an allocator specific context
  			// which is a child of the passed in context to hold
  			// allocator specific state
  			watch, watchCancel, err := a.init(ctx, aaPtr)
  			if err != nil {
  				return err
  			}
  
  			wg.Add(1)
  			go func(watch <-chan events.Event, watchCancel func()) {
  				defer func() {
  					wg.Done()
  					watchCancel()
  				}()
  				a.run(ctx, *aaPtr, watch)
  			}(watch, watchCancel)
  			return nil
  		}
  
  		actors = append(actors, actor)
  	}
  
  	for _, actor := range actors {
  		if err := actor(); err != nil {
  			return err
  		}
  	}
  
  	<-a.stopChan
  	return nil
  }
docs: // Run starts all allocator go-routines and waits for Stop to be called.