Skip to content

Commit

Permalink
jcall: Add -W (wait-at-exit) flag
Browse files Browse the repository at this point in the history
  • Loading branch information
creachadair committed Oct 8, 2021
1 parent 3434323 commit 78eae1b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tools/jcall/jcall.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"log"
"net"
"os"
"os/signal"
"path/filepath"
"strings"
"time"
Expand All @@ -37,6 +38,7 @@ var (
doIndent = flag.Bool("i", false, "Indent JSON output")
doMulti = flag.Bool("m", false, "Issue the same call repeatedly with different arguments")
doTiming = flag.Bool("T", false, "Print call timing stats")
doWaitExit = flag.Bool("W", false, "Wait for interrupt at exit")
withLogging = flag.Bool("v", false, "Enable verbose logging")
withMeta = flag.String("meta", "", "Attach this JSON value as request metadata (implies -c)")
)
Expand Down Expand Up @@ -125,6 +127,7 @@ func main() {
if err != nil {
log.Fatalf("Dial %q: %v", flag.Arg(0), err)
}
defer ch.Close()
cc = ch
} else if nc := newFraming(*chanFraming); nc == nil {
log.Fatalf("Unknown channel framing %q", *chanFraming)
Expand All @@ -139,6 +142,12 @@ func main() {
}
tdial := time.Now()

done := make(chan os.Signal, 1)
if *doWaitExit {
signal.Notify(done, os.Interrupt)
} else {
close(done)
}
cli := newClient(cc)
pdur, err := issueCalls(ctx, cli, flag.Args()[1:])
// defer failure on error till after we print aggregate timing stats
Expand All @@ -155,6 +164,10 @@ func main() {
if err != nil {
os.Exit(1)
}
if *doWaitExit {
log.Print("<waiting at exit>")
}
<-done
}

func newClient(conn channel.Channel) *jrpc2.Client {
Expand Down

0 comments on commit 78eae1b

Please sign in to comment.