|
@ -1,20 +1,19 @@ |
|
|
package channel |
|
|
package channel |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
plnModel "LAPP_ACURA_MOM_BACKEND/models/pln" |
|
|
|
|
|
"errors" |
|
|
"errors" |
|
|
"sync" |
|
|
"sync" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
type ReleaseTaskChannel struct { |
|
|
type ReleaseTaskChannel struct { |
|
|
c chan plnModel.CustOrder |
|
|
|
|
|
|
|
|
c chan interface{} |
|
|
closed bool |
|
|
closed bool |
|
|
mutex sync.Mutex |
|
|
mutex sync.Mutex |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func NewReleaseChannel() *ReleaseTaskChannel { |
|
|
func NewReleaseChannel() *ReleaseTaskChannel { |
|
|
return &ReleaseTaskChannel{ |
|
|
return &ReleaseTaskChannel{ |
|
|
c: make(chan plnModel.CustOrder, 100), |
|
|
|
|
|
|
|
|
c: make(chan interface{}, 100), |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -26,13 +25,13 @@ func (c *ReleaseTaskChannel) IsClosed() bool { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// SendData 发送数据
|
|
|
// SendData 发送数据
|
|
|
func (c *ReleaseTaskChannel) SendData(custOrder plnModel.CustOrder) error { |
|
|
|
|
|
|
|
|
func (c *ReleaseTaskChannel) SendData(data interface{}) error { |
|
|
c.mutex.Lock() |
|
|
c.mutex.Lock() |
|
|
defer c.mutex.Unlock() |
|
|
defer c.mutex.Unlock() |
|
|
if c.closed { |
|
|
if c.closed { |
|
|
return errors.New("管道已关闭") |
|
|
return errors.New("管道已关闭") |
|
|
} |
|
|
} |
|
|
c.c <- custOrder |
|
|
|
|
|
|
|
|
c.c <- data |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -46,7 +45,7 @@ func (c *ReleaseTaskChannel) Close() { |
|
|
c.closed = true |
|
|
c.closed = true |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (c *ReleaseTaskChannel) Read() (data plnModel.CustOrder, ok bool, err error) { |
|
|
|
|
|
|
|
|
func (c *ReleaseTaskChannel) Read() (data interface{}, ok bool, err error) { |
|
|
c.mutex.Lock() |
|
|
c.mutex.Lock() |
|
|
if c.closed { |
|
|
if c.closed { |
|
|
err = errors.New("管道已关闭") |
|
|
err = errors.New("管道已关闭") |
|
@ -65,6 +64,6 @@ func (c *ReleaseTaskChannel) ResetChannel() (err error) { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
c.closed = false |
|
|
c.closed = false |
|
|
c.c = make(chan plnModel.CustOrder, 50) |
|
|
|
|
|
|
|
|
c.c = make(chan interface{}, 50) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |