diff --git a/types/cote/cote-tests.ts b/types/cote/cote-tests.ts index a425634dab..75e9b70071 100644 --- a/types/cote/cote-tests.ts +++ b/types/cote/cote-tests.ts @@ -344,4 +344,50 @@ class InitialObservations { new cote.Requester({ name: 'OwnStatusReporter' }, { statusInterval: 100 }); } + + callbackApi() { + // Added to Readme above, near respective Promise examples. + } + + timeBalancedRequester() { + const randomRequester = new cote.TimeBalancedRequester({ + name: 'Random Requester', + namespace: 'rnd', + key: 'a certain key', + requests: ['randomRequest'] + }); + + const req = { + type: 'randomRequest', + payload: { + val: Math.floor(Math.random() * 10) + } + }; + + randomRequester.send(req) + .then(console.log) + .catch(console.log) + .then(() => process.exit()); + } + + pendingBalancedRequester() { + const randomRequester = new cote.PendingBalancedRequester({ + name: 'Random Requester', + namespace: 'rnd', + key: 'a certain key', + requests: ['randomRequest'] + }); + + const req = { + type: 'randomRequest', + payload: { + val: Math.floor(Math.random() * 10) + } + }; + + randomRequester.send(req) + .then(console.log) + .catch(console.log) + .then(() => process.exit()); + } } diff --git a/types/cote/index.d.ts b/types/cote/index.d.ts index c49411f813..5b8df3edf1 100644 --- a/types/cote/index.d.ts +++ b/types/cote/index.d.ts @@ -218,6 +218,36 @@ export function MonitoringTool(port: number): { server: Server }; +/** + * Takes average response times of each connected socket and balances requests + * among them accordingly. + */ +export class TimeBalancedRequester extends Requester { + /** + * How long to wait for response before neglecting its calculation time, + * in milliseconds. + */ + CALCULATION_TIMEOUT: number; + + /** + * How many requests to make before exploring a random server for response + * time improvement. + */ + MAX_REQUESTS: number; + + /** + * How often to check whether a response arrived. Readonly because used in + * constructor right after being set. + */ + readonly SAMPLE_INTERVAL: number; +} + +/** + * Keeps track of open, pending requests for each known Responder. Each new + * request goes to the Responder with the minimum open requests. + */ +export class PendingBalancedRequester extends Requester { } + /** * Action is nothing but object with `type`. */