git.frostfs.info/TrueCloudLab/frostfs-sdk-go@v0.0.0-20241022124111-5361f0ecebd3/object/transformer/channel.go (about) 1 package transformer 2 3 import ( 4 "context" 5 6 objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" 7 ) 8 9 type chanTarget struct { 10 ch chan<- *objectSDK.Object 11 } 12 13 // NewChannelTarget returns ObjectTarget which writes 14 // object parts to a provided channel. 15 func NewChannelTarget(ch chan<- *objectSDK.Object) ObjectWriter { 16 return &chanTarget{ 17 ch: ch, 18 } 19 } 20 21 func (c *chanTarget) WriteObject(ctx context.Context, o *objectSDK.Object) error { 22 select { 23 case c.ch <- o: 24 case <-ctx.Done(): 25 return ctx.Err() 26 } 27 return nil 28 }