Skip to content

Commit

Permalink
history: wait for pty to process all commands before we cancel the co…
Browse files Browse the repository at this point in the history
…ntext
  • Loading branch information
joshi4 committed Mar 7, 2024
1 parent 2d6abb2 commit 84d0a8c
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions cmd/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"log/slog"
"os"
"sync"
"time"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/huh"
Expand Down Expand Up @@ -160,19 +161,19 @@ func expandHistory(logger *slog.Logger, sh shell.Shell, rawCommands []string) ([
}
ptmx.Write([]byte{4}) // EOT

// time.Sleep(1 * time.Second)
logger.Debug("cancel context for shell expanding history")
cancelCtx()
logger.Debug("waiting for expanding history shell to finish")
c.Wait()
logger.Debug("shell finished expanding history")
logger.Debug("closing pty")
if err := ptmx.Close(); err != nil {
logger.Debug("failed to close pty", "error", err.Error())
for len(ss.Commands()) < len(rawCommands) {
// wait for all commands to be processed
logger.Debug("waiting for all commands to be processed", "processed", len(ss.Commands()), "total", len(rawCommands))
time.Sleep(1 * time.Second)
}
logger.Debug("waiting for waitGroup to finish", "function", "expandHistory")

logger.Debug("waiting for wg.Wait()")
wg.Wait()
logger.Debug("waitGroup finished", "function", "expandHistory")
logger.Debug("wg.Wait() finished")
logger.Debug("waitng for c.Wait()")
cancelCtx()
c.Wait()
logger.Debug("c.Wait() finished")
return ss.Commands(), nil
}

Expand Down

0 comments on commit 84d0a8c

Please sign in to comment.