diff --git a/src/source-discovery.ts b/src/source-discovery.ts index aeec3b8..6effc05 100644 --- a/src/source-discovery.ts +++ b/src/source-discovery.ts @@ -4,7 +4,7 @@ import { GatewaySession, } from './gateway-session' import { GatewayRequest, Item, Query, QueryMethod } from './protobuf' -import { getUniqueAttributeValue, newDuration } from './util' +import { getUniqueAttributeValue, newDeadline } from './util' export enum DiscoveryField { TYPE = 0, @@ -111,7 +111,7 @@ export class SourceDiscovery extends EventTarget { value: new Query({ scope: 'global', method: QueryMethod.LIST, - timeout: newDuration(5000), + deadline: newDeadline(5000), UUID: parse(v4()), type, }), diff --git a/src/util.ts b/src/util.ts index 44dab87..bb21c97 100644 --- a/src/util.ts +++ b/src/util.ts @@ -57,6 +57,17 @@ export function newDuration(ms: number): Duration { return d } +/** + * Converts a number of milliseconds to a protobuf Timestamp that number of milliseconds in the future. + * + * @param ms The number of milliseconds + * @returns A timestamp in protobuf format + */ +export function newDeadline(ms: number): Timestamp { + const deadline = new Date(Date.now() + ms) + return Timestamp.fromDate(deadline) +} + /** * Gets the value of a particular attribute. *Note:* that this only supports * attributes at the top level currently