Skip to content
Myr

fix(tea): allocate msgs channel in constructor

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Race condition bug: Start() is called in a new gorotuine, then Send(). If the Send happens before the msgs channel is allocated, the message is dropped. Instead allocate the channel in the constructor, so msgs is never nil.

authored by Christian Stewart · committed by Christian Rocha · parent 66cea09 · Browse files · 1 file+2 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Signed-off-by: Christian Stewart <christian@paral.in>

Diff stats

1 file+2 added−5 removed

  • other:+2 added−5 removed

1 file+2 added−5 removed

modified:tea.go+2 added-5 removed
237 unmodified lines
238 mtx: &sync.Mutex{},239 initialModel: model,240 output: os.Stdout,241 input: os.Stdin,242 msgs: make(chan Msg),243 CatchPanics: true,244 }245246 // Apply all options to the program.
5 unmodified lines
252}253254// StartReturningModel initializes the program. Returns the final model.255func (p *Program) StartReturningModel() (Model, error) {255 p.msgs = make(chan Msg)256256 var (257 cmds = make(chan Cmd)258 errs = make(chan error)259 )
292 unmodified lines
552//553// This method is currently provisional. The method signature may alter554// slightly, or it may be removed in a future version of this package.555func (p *Program) Send(msg Msg) {557 if p.msgs != nil {558 p.msgs <- msg556 p.msgs <- msg559 }557}558559// Quit is a convenience function for quitting Bubble Tea programs. Use it560// when you need to shut down a Bubble Tea program from the outside.
106 unmodified lines