use reflect select
This commit is contained in:
parent
03ca08d9bf
commit
8cb14335c3
@ -174,15 +174,26 @@ func (c *client) makeOutChan(ctx context.Context, ftyp reflect.Type, valOut int)
|
|||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for buf.Len() > 0 {
|
for buf.Len() > 0 {
|
||||||
select {
|
|
||||||
case <- chCtx.Done():
|
|
||||||
buf.Init()
|
|
||||||
default:
|
|
||||||
front := buf.Front()
|
front := buf.Front()
|
||||||
bufLk.Unlock()
|
bufLk.Unlock()
|
||||||
|
|
||||||
ch.Send(front.Value.(reflect.Value).Elem())
|
cases := []reflect.SelectCase{
|
||||||
|
{
|
||||||
|
Dir: reflect.SelectRecv,
|
||||||
|
Chan: reflect.ValueOf(chCtx.Done()),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Dir: reflect.SelectSend,
|
||||||
|
Chan: ch,
|
||||||
|
Send: front.Value.(reflect.Value).Elem(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
switch chosen, _, _ := reflect.Select(cases); chosen {
|
||||||
|
case 0:
|
||||||
|
bufLk.Lock()
|
||||||
|
buf.Init()
|
||||||
|
case 1:
|
||||||
bufLk.Lock()
|
bufLk.Lock()
|
||||||
buf.Remove(front)
|
buf.Remove(front)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user