Documentation
¶
Overview ¶
Package matchmaking provides group formation: members enter a queue tagged with attributes; a Matcher periodically searches for satisfying subsets of a configured group size; matches are emitted to subscribers.
Supports a solo-fallback policy: if no full group forms within a TTL, the member is emitted in a solo Match so the caller can offer a single- player path.
Domain-agnostic; common applications:
- Game matchmaking (mission + difficulty + region).
- Collaborative editing — assemble a doc-edit session of N peers.
- Group call / video conferencing — find available callees.
- Support routing — pair a ticket with N agents with the right skills.
- Carpooling — match riders by route + time + capacity.
The package ships an in-memory Pool; Redis-backed and Open Match adapters are pluggable via the Backend interface.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrAlreadyEnqueued = errors.New("matchmaking: member already enqueued") ErrNotEnqueued = errors.New("matchmaking: member not enqueued") )
Errors surfaced by Pool.
Functions ¶
This section is empty.
Types ¶
type FirstN ¶
type FirstN struct {
N int
}
FirstN is a Matcher that pairs the first N members in queue order regardless of attributes. Useful for fastest-match modes.
type Match ¶
Match is the result of a successful pairing. Solo is true when the match was emitted via the solo-fallback policy rather than full group formation.
type Matcher ¶
Matcher inspects the current candidate pool and returns a satisfying subset, or nil if no match is currently possible. Implementations should be cheap — the Pool calls Match per tick.
type MatcherFunc ¶
MatcherFunc adapts a function to the Matcher interface.
func (MatcherFunc) Match ¶
func (f MatcherFunc) Match(c []Member) []Member
type MemberID ¶
type MemberID string
MemberID is opaque caller-supplied identity for a queued participant.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool holds the queue and emits matches via Subscribe.
func NewPool ¶
func NewPool(cfg PoolConfig) *Pool
NewPool constructs a Pool. Panics if config is invalid.
type PoolConfig ¶
type PoolConfig struct {
// Name is an optional label used in logs / metrics.
Name string
// GroupSize is the exact party size produced by a full match. The
// Matcher is expected to return slices of this length.
GroupSize int
// Matcher decides who pairs with whom. Required.
Matcher Matcher
// SoloFallback is the duration after which a queued member is emitted
// as a Match with Solo=true. Zero disables solo fallback.
SoloFallback time.Duration
// TickInterval controls how often Run scans for matches. Defaults to
// 100ms if unset.
TickInterval time.Duration
// Clock supplies the current time; defaults to time.Now if nil.
Clock func() time.Time
}
PoolConfig configures a Pool.
type SameAttribute ¶
SameAttribute is a Matcher that pairs the first N candidates sharing the same value for AttrKey (e.g. region, mission, difficulty).
func (SameAttribute) Match ¶
func (m SameAttribute) Match(candidates []Member) []Member