Skip to content
Classcorev0.12.0

Subscriber

Abstract base class for handling application subscribers.

Pass the subscription key(s) as the generic, the same one(s) as @Subscribe. On a single-key subscriber, read this.data directly. On a subscriber for several keys, branch with this.match, keyed by subscription key.

abstract class Subscriber<
    Keys extends SubscriptionKey,
    TCore extends CoreBase
>

Member visibility

Filter class members by access level.

constructor

Constructs a new instance of the Subscriber class

Subscriber(payload: AllSubscriptions[Keys], core: TCore, key: Keys)

Showing members with Protected visibility and higher.

Keys

One or more subscription keys, like 'userJoin' or 'userJoin' | 'userLeave'.

Keys extends SubscriptionKey

TCore

The transport's Core

TCore extends CoreBase

core

protected readonly core: TCore

data

The published payload. It's never on a subscriber for several keys, where this.match reads it.

protected data: SingleKeyData<Keys>

key

protected readonly key: Keys

logger

protected readonly logger: Logger

execute()

Executes the subscriber handler logic.

public abstract execute(): Promise<void>

match()

Run the case for the published key. Use this only when the subscriber is registered for several keys. On a single-key subscriber, read this.data directly.

Provide one case per registered key. Each case receives that key's own payload. A missing key or an unknown key is a compile error.

protected async match<Ret, Cases>(
    cases: OnlyCases<Cases, SubscriberMatchCases<Keys, Ret>>
): Promise<MatchResult<Ret, Cases>>
Type parameter: Ret

The type that every case must return. Leave it out to get the union of what the cases return.

Throws:

A SeedcordTypeError with MatchCaseMissing when the published key doesn't have a case.