streamdata: optionally reuse buffer
This enables use of stdlib iterator helpers. Signed-off-by: Yonah <contrib@gensokyo.uk>
This commit is contained in:
@@ -276,7 +276,10 @@ func (c *Channel) Path(ident *Ident) string {
|
||||
// All returns an iterator over all known [Ident] in the on-disk representation.
|
||||
// Iteration stops when encountering the first non-nil error, and its value is
|
||||
// saved to the value pointed to by errP.
|
||||
func (c *Channel) All(errP *error) iter.Seq[*Ident] {
|
||||
//
|
||||
// If reuse is true, the same value is updated every iteration and the same
|
||||
// address is yileded as a result.
|
||||
func (c *Channel) All(errP *error, reuse bool) iter.Seq[*Ident] {
|
||||
return func(yield func(*Ident) bool) {
|
||||
dents, err := c.root.FS().(fs.ReadDirFS).ReadDir(channelPathVOD)
|
||||
if err != nil {
|
||||
@@ -298,7 +301,11 @@ func (c *Channel) All(errP *error) iter.Seq[*Ident] {
|
||||
return
|
||||
}
|
||||
|
||||
if !yield(&ident) {
|
||||
p := &ident
|
||||
if !reuse {
|
||||
p = new(ident)
|
||||
}
|
||||
if !yield(p) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user