Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ExpiringServiceDiscovery<S>

Discovery implementation that supports expiring services after a certain amount of time.

class CustomServiceDiscovery extends ExpiringServiceDiscovery {
constructor() {
super('discovery-id-here', {
expirationTime: 30*60*1000 // expire after 30 minutes
});
}
}

Type parameters

Hierarchy

Index

Constructors

constructor

Properties

Protected Readonly availableEvent

availableEvent: Event<ExpiringServiceDiscovery<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<ExpiringServiceDiscovery<S>, [service: S]>

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

Protected Readonly updateEvent

updateEvent: Event<ExpiringServiceDiscovery<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]>
  • Event emitted whenever a service is detected to be unavailable.

    Returns Subscribable<this, [service: S]>

onUpdate

  • get onUpdate(): Subscribable<this, [service: S, previousService: S]>
  • Event emitted when a service is available and is updated.

    Returns 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 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