Skip to content

Commit

Permalink
Fix query timeout->deadline
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidS-ovm committed Sep 15, 2023
1 parent 454c514 commit 57e5f91
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/source-discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}),
Expand Down
11 changes: 11 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 57e5f91

Please sign in to comment.