MCPcopy Create free account
hub / github.com/charmbracelet/bubbletea / handleCommands

Method handleCommands

tea.go:750–789  ·  view source on GitHub ↗

handleCommands runs commands in a goroutine and sends the result to the program's message channel.

(cmds chan Cmd)

Source from the content-addressed store, hash-verified

748// handleCommands runs commands in a goroutine and sends the result to the
749// program's message channel.
750func (p *Program) handleCommands(cmds chan Cmd) chan struct{} {
751 ch := make(chan struct{})
752
753 go func() {
754 defer close(ch)
755
756 for {
757 select {
758 case <-p.ctx.Done():
759 return
760
761 case cmd := <-cmds:
762 if cmd == nil {
763 continue
764 }
765
766 // Don't wait on these goroutines, otherwise the shutdown
767 // latency would get too large as a Cmd can run for some time
768 // (e.g. tick commands that sleep for half a second). It's not
769 // possible to cancel them so we'll have to leak the goroutine
770 // until Cmd returns.
771 go func() {
772 // Recover from panics.
773 if !p.disableCatchPanics {
774 defer func() {
775 if r := recover(); r != nil {
776 p.recoverFromPanic(r)
777 }
778 }()
779 }
780
781 msg := cmd() // this can be long.
782 p.Send(msg)
783 }()
784 }
785 }
786 }()
787
788 return ch
789}
790
791// eventLoop is the central message loop. It receives and handles the default
792// Bubble Tea messages, update the model and triggers redraws.

Callers 1

RunMethod · 0.95

Calls 2

recoverFromPanicMethod · 0.95
SendMethod · 0.95

Tested by

no test coverage detected