github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/pkg/interactive/interactive_client_cancel.go (about)

     1  package interactive
     2  
     3  import (
     4  	"context"
     5  	"log"
     6  )
     7  
     8  // create a cancel context for the interactive prompt, and set c.cancelFunc
     9  func (c *InteractiveClient) createPromptContext(parentContext context.Context) context.Context {
    10  	// ensure previous prompt is cleaned up
    11  	if c.cancelPrompt != nil {
    12  		c.cancelPrompt()
    13  	}
    14  	ctx, cancel := context.WithCancel(parentContext)
    15  	c.cancelPrompt = cancel
    16  	return ctx
    17  }
    18  
    19  func (c *InteractiveClient) createQueryContext(ctx context.Context) context.Context {
    20  	ctx, cancel := context.WithCancel(ctx)
    21  	c.cancelActiveQuery = cancel
    22  	return ctx
    23  }
    24  
    25  func (c *InteractiveClient) cancelActiveQueryIfAny() {
    26  	if c.cancelActiveQuery != nil {
    27  		log.Println("[INFO] cancelActiveQueryIfAny CALLING cancelActiveQuery")
    28  		c.cancelActiveQuery()
    29  		c.cancelActiveQuery = nil
    30  	} else {
    31  		log.Println("[INFO] cancelActiveQueryIfAny NO active query")
    32  	}
    33  }