chore: optimize batches with one item (#875)

Signed-off-by: Andres Taylor <andres@planetscale.com>
This commit is contained in:
Andrés Taylor 2024-03-01 20:18:47 +01:00 committed by GitHub
parent f633b8f0e3
commit 305d5b285f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -20,11 +20,15 @@ func Batch(cmds ...Cmd) Cmd {
}
validCmds = append(validCmds, c)
}
if len(validCmds) == 0 {
switch len(validCmds) {
case 0:
return nil
}
return func() Msg {
return BatchMsg(validCmds)
case 1:
return validCmds[0]
default:
return func() Msg {
return BatchMsg(validCmds)
}
}
}