network

package
v0.0.0-...-18e7427 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Events

type Events[T any] struct {
	// contains filtered or unexported fields
}

func NewEvents

func NewEvents[T any]() *Events[T]

func (*Events[T]) AddListener

func (e *Events[T]) AddListener(listeners ...PacketHandler[T])

AddListener adds a listener to the event. The listener will be called when the packet with the same ID is received. The listener will be called in the order of priority. The listeners cannot have multiple same ID.

func (*Events[T]) AddTicker

func (e *Events[T]) AddTicker(tickers ...TickHandler[T])

func (*Events[T]) GetHandlers

func (e *Events[T]) GetHandlers(id int32) *HandlerHeap[T]

type HandlerHeap

type HandlerHeap[T any] []PacketHandler[T]

HandlerHeap is PriorityQueue<PacketHandlerFunc>

func (HandlerHeap[T]) Len

func (h HandlerHeap[T]) Len() int

func (HandlerHeap[T]) Less

func (h HandlerHeap[T]) Less(i, j int) bool

func (*HandlerHeap[T]) Pop

func (h *HandlerHeap[T]) Pop() interface{}

func (*HandlerHeap[T]) Push

func (h *HandlerHeap[T]) Push(x interface{})

func (HandlerHeap[T]) Swap

func (h HandlerHeap[T]) Swap(i, j int)

type PacketHandler

type PacketHandler[T any] struct {
	ID       int32
	Priority int
	F        func(*T, pk.Packet) error
}

type PacketQueue

type PacketQueue struct {
	// contains filtered or unexported fields
}

func NewPacketQueue

func NewPacketQueue() (p *PacketQueue)

func (*PacketQueue) Close

func (p *PacketQueue) Close()

func (*PacketQueue) Pull

func (p *PacketQueue) Pull() (packet pk.Packet, ok bool)

func (*PacketQueue) Push

func (p *PacketQueue) Push(packet pk.Packet)

type TickHandler

type TickHandler[T any] struct {
	Priority int
	F        func(*T) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL