Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TimedServiceDiscovery<S>

Service discovery that combines service expiry with a timed discovery. Makes it easy to perform searches at a timed interval.

class CustomServiceDiscovery extends TimedServiceDiscovery {
constructor() {
super('discovery-id', {
expirationTime: 30*60*1000, // remove services after 30 minutes
searchTime: 5*60*1000 // search every 5 minutes
});

// Perform an initial search
this.search();
}

protected search() {
// Search for services here
}
}

Type parameters

Hierarchy

Index

Constructors

constructor

Properties

Protected Readonly availableEvent

availableEvent: Event<TimedServiceDiscovery<S>, [service: S]>

Event used to emit when a service is available.

Protected Readonly debug

debug: Debugger

Debugger that can be used to output debug messages for the discovery.

Readonly expirationTime

expirationTime: number

Protected Readonly unavailableEvent

unavailableEvent: Event<TimedServiceDiscovery<S>, [service: S]>

Event used to emit when a service is no longer available.

Protected Readonly updateEvent

updateEvent: Event<TimedServiceDiscovery<S>, [service: S, previousService: S]>

Event used to emit when a service has been updated.

Accessors

destroyed

  • get destroyed(): boolean

onAvailable

  • get onAvailable(): Subscribable<this, [service: S]>

onDestroy

  • get onDestroy(): Subscribable<this, []>

onError

  • get onError(): Subscribable<this, [err: Error]>

onUnavailable

  • get onUnavailable(): Subscribable<this, [service: S]>

onUpdate

  • get onUpdate(): Subscribable<this, [service: S, previousService: S]>

services

  • get services(): S[]

Methods

and

destroy

  • destroy(): Promise<void>

filter

find

findAll

get

  • get(id: string): null | S

Protected logAndEmitError

  • logAndEmitError(error: unknown, message?: string): void

map

Protected removeExpiredServices

  • removeExpiredServices(timePassed?: number): void

Protected removeService

  • removeService(service: string | S): null | S

Protected Abstract search

  • search(): void

Protected setServices

  • setServices(available: Iterable<S>): void

Protected updateService

  • updateService(service: S, expirationTime?: number): null | S
  • Add or update a service that has been found. This will register the service and emit suitable events. Services are identified internally using their identifier. Services will be treated as new if their id does is not currently tracked, and as updates if their id is currently tracked.

    Parameters

    • service: S
    • Optional expirationTime: number

    Returns null | S

    previous service or null if not registered

Generated using TypeDoc