Commit 34086771 authored by suyanlong's avatar suyanlong

optimized appchain struct

parent 5aaf11a4
......@@ -28,6 +28,7 @@ type appChain struct {
ctx context.Context
cancel context.CancelFunc
cryptor txcrypto.Cryptor
msgCh chan *pb.Message
}
func NewPort(client plugins.Client, cryptor txcrypto.Cryptor, logger logrus.FieldLogger) (port.Port, error) {
......@@ -39,6 +40,7 @@ func NewPort(client plugins.Client, cryptor txcrypto.Cryptor, logger logrus.Fiel
recvCh: make(chan *pb.IBTP, 1024),
ctx: ctx,
cancel: cancel,
msgCh: make(chan *pb.Message, 10),
}, nil
}
......
......@@ -79,7 +79,6 @@ func (a *appChain) AsyncSend(msg *pb.Message) error {
// ListenIBTPX 监听IBTPX数据。
func (a *appChain) ListenIBTPX() <-chan *pb.Message {
ibtpCh := a.ListenIBTP()
msgCh := make(chan *pb.Message, 10)
func() {
for {
select {
......@@ -87,13 +86,13 @@ func (a *appChain) ListenIBTPX() <-chan *pb.Message {
//TODO ibtp to ibtpx
data, _ := ibtp.Marshal()
msg := pb.Msg(pb.Message_IBTP_SEND, true, data)
msgCh <- msg
a.msgCh <- msg
case <-a.ctx.Done():
break
}
}
}()
return msgCh
return a.msgCh
}
// 同一个接口,不同的实现,行为可以不一样。
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment