frostfs-sdk-go/object/transformer/channel.go
Dmitrii Stepanov c359a7465a [#64] transformer: Simplify interface
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-07-11 07:33:12 +00:00

28 lines
529 B
Go

package transformer
import (
"context"
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
)
type chanTarget struct {
ch chan<- *objectSDK.Object
}
// NewChannelTarget returns ObjectTarget which writes
// object parts to a provided channel.
func NewChannelTarget(ch chan<- *objectSDK.Object) ObjectWriter {
return &chanTarget{
ch: ch,
}
}
func (c *chanTarget) WriteObject(ctx context.Context, o *objectSDK.Object) error {
select {
case c.ch <- o:
case <-ctx.Done():
return ctx.Err()
}
return nil
}