feat(structure): add channelx

This commit is contained in:
bandl 2021-11-29 23:35:18 +08:00
parent a949ab2edc
commit f62a59b551
2 changed files with 9 additions and 1 deletions

View File

@ -51,9 +51,16 @@ func (c *ChannelX) Push(value string) structure.UpdateLength {
func (c *ChannelX) Pop() (string, structure.UpdateLength) {
val := <-c.channel
return val.ToString(), structure.UpdateLength(val.GetSize())
return val.ToString(), structure.UpdateLength(val.GetSize()) * -1
}
func (c *ChannelX) Length() int {
return len(c.channel)
}
func (c *ChannelX) CLean() structure.UpdateLength {
c.channel = make(chan *structure.Value, cap(c.channel))
up := c.sizeByte
c.sizeByte = 0
return structure.UpdateLength(up) * -1
}

View File

@ -73,4 +73,5 @@ type ChannelXInterface interface {
Push(value string) UpdateLength
Pop() (string, UpdateLength)
Length() int
Clean() UpdateLength
}