github.com/databricks/cli@v0.203.0/bundle/deferred.go (about)

     1  package bundle
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/databricks/cli/libs/errs"
     7  )
     8  
     9  type DeferredMutator struct {
    10  	mutator Mutator
    11  	finally Mutator
    12  }
    13  
    14  func (d *DeferredMutator) Name() string {
    15  	return "deferred"
    16  }
    17  
    18  func Defer(mutator Mutator, finally Mutator) Mutator {
    19  	return &DeferredMutator{
    20  		mutator: mutator,
    21  		finally: finally,
    22  	}
    23  }
    24  
    25  func (d *DeferredMutator) Apply(ctx context.Context, b *Bundle) error {
    26  	mainErr := Apply(ctx, b, d.mutator)
    27  	errOnFinish := Apply(ctx, b, d.finally)
    28  	if mainErr != nil || errOnFinish != nil {
    29  		return errs.FromMany(mainErr, errOnFinish)
    30  	}
    31  
    32  	return nil
    33  }