Skip to content

Commit

Permalink
loop on resultSet
Browse files Browse the repository at this point in the history
  • Loading branch information
dudo committed Nov 29, 2023
1 parent aa79456 commit ff0db4b
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

func main() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
defer cancel()

// Create a Pixie client with local standalonePEM listening address
client, err := pxapi.NewClient(
Expand Down Expand Up @@ -45,29 +45,37 @@ func main() {
}
pxl := string(content)

// Execute the PxL script and get the resultSet
resultSet, err := vz.ExecuteScript(ctx, pxl, tm)
if err != nil {
log.Fatalf("Failed to execute script: %v", err)
}
defer resultSet.Close()

// Loop to receive the PxL script results.
for {
err := resultSet.Stream()
// Execute the PxL script and check for resultSet
resultSet, err := vz.ExecuteScript(ctx, pxl, tm)
if err != nil {
if err == io.EOF || err == context.Canceled {
// End of stream
break
}
if errdefs.IsCompilationError(err) {
log.Printf("Compilation error: %v", err)
break
log.Fatalf("Failed to execute script: %v", err)
}
defer resultSet.Close()

for {
// Receive the PxL script results.
err := resultSet.Stream()
if err != nil {
if err == io.EOF {
// End of stream, break inner loop to reopen stream
break
}
if err == context.Canceled {
log.Fatalf("Context canceled: %v", err)
}
if err.Error() == "stream has already been closed" {
log.Fatalf("Stream unexpectedly closed: %v", err)
}
if errdefs.IsCompilationError(err) {
log.Fatalf("Compilation error: %v", err)
}
// Handle other kinds of runtime errors

log.Fatalf("Stream error: %v", err)
}
// Handle other kinds of runtime errors

log.Printf("Stream error: %v", err)
}
time.Sleep(time.Second)
}
}

Expand Down

0 comments on commit ff0db4b

Please sign in to comment.