Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: tea.Batch() returns nil if all Cmds were nil #200

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions tea.go
Expand Up @@ -111,6 +111,8 @@ type Program struct {

// Batch performs a bunch of commands concurrently with no ordering guarantees
// about the results. Use a Batch to return several commands.
// If the slice of commands has a length of 0 or only contains nil commands,
// the function itself returns nil.
//
// Example:
//
Expand All @@ -122,6 +124,17 @@ func Batch(cmds ...Cmd) Cmd {
if len(cmds) == 0 {
return nil
}

nilCount := 0
for _, cmd := range cmds {
if cmd == nil {
nilCount++
}
}
if nilCount == len(cmds) {
return nil
}

return func() Msg {
return batchMsg(cmds)
}
Expand Down