2023-02-23 14:13:27 +00:00
|
|
|
package transformer
|
|
|
|
|
|
|
|
import (
|
2023-04-21 10:04:44 +00:00
|
|
|
"context"
|
|
|
|
|
2023-03-16 06:51:03 +00:00
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2023-02-23 14:13:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type chanTarget struct {
|
2023-07-07 12:34:31 +00:00
|
|
|
ch chan<- *objectSDK.Object
|
2023-02-23 14:13:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewChannelTarget returns ObjectTarget which writes
|
|
|
|
// object parts to a provided channel.
|
2023-07-07 12:34:31 +00:00
|
|
|
func NewChannelTarget(ch chan<- *objectSDK.Object) ObjectWriter {
|
2023-02-23 14:13:27 +00:00
|
|
|
return &chanTarget{
|
|
|
|
ch: ch,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-07 12:34:31 +00:00
|
|
|
func (c *chanTarget) WriteObject(ctx context.Context, o *objectSDK.Object) error {
|
2023-04-21 10:04:44 +00:00
|
|
|
select {
|
2023-07-07 12:34:31 +00:00
|
|
|
case c.ch <- o:
|
2023-04-21 10:04:44 +00:00
|
|
|
case <-ctx.Done():
|
2023-07-07 12:34:31 +00:00
|
|
|
return ctx.Err()
|
2023-04-21 10:04:44 +00:00
|
|
|
}
|
2023-07-07 12:34:31 +00:00
|
|
|
return nil
|
2023-02-23 14:13:27 +00:00
|
|
|
}
|