Ejemplo n.º 1
0
//只是写出去
func (self *RemotingClient) Write(p packet.Packet) (*turbo.Future, error) {

	pp := &p
	opaque := self.fillOpaque(pp)
	future := turbo.NewFuture(opaque, self.localAddr)
	self.rc.RequestHolder.Attach(opaque, future)
	return future, self.remoteSession.Write(pp)
}
Ejemplo n.º 2
0
//写数据并且得到相应
func (self *RemotingClient) WriteAndGet(p packet.Packet,
	timeout time.Duration) (interface{}, error) {

	pp := &p
	opaque := self.fillOpaque(pp)
	future := turbo.NewFuture(opaque, self.localAddr)
	self.rc.RequestHolder.Attach(opaque, future)
	err := self.remoteSession.Write(pp)
	// //同步写出
	// future, err := self.Write(p)
	if nil != err {
		return nil, err
	}

	tid, ch := self.rc.TW.After(timeout, func() {
	})

	resp, err := future.Get(ch)
	self.rc.TW.Remove(tid)
	return resp, err

}