github.com/hsfzxjy/dgo/go@v0.2.0/port.go (about)

     1  package dgo
     2  
     3  import (
     4  	"fmt"
     5  	"reflect"
     6  	"sync/atomic"
     7  
     8  	xsync "github.com/puzpuzpuz/xsync/v2"
     9  )
    10  
    11  type Port struct {
    12  	sendPortKey    PortKey
    13  	receivePortKey PortKey
    14  	goCallbacks    *xsync.MapOf[uint64, reflect.Value]
    15  	nextCallbackId atomic.Uint32
    16  	isClosed       atomic.Bool
    17  }
    18  
    19  func newPort(sendPortKey PortKey, receivePortKey PortKey) *Port {
    20  	return &Port{
    21  		sendPortKey:    sendPortKey,
    22  		receivePortKey: receivePortKey,
    23  		goCallbacks:    xsync.NewIntegerMapOf[uint64, reflect.Value](),
    24  	}
    25  }
    26  
    27  func (p *Port) key() PortKey { return p.receivePortKey }
    28  
    29  func (p *Port) String() string {
    30  	return fmt.Sprintf("Port[S=%016X, R=%016X]", p.sendPortKey, p.receivePortKey)
    31  }