Skip to content

Commit

Permalink
Add support for timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
myrotvorets-team committed May 22, 2022
1 parent c6c038a commit 7740e55
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/clientbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class ClientBase {
private _transport: IRemoteTransport;
private readonly _encoder: IFaceXRequestEncoder;
protected _requestBuilder: IFaceXRequestBuilder;
private _timeout = 15000;

public constructor(
url: string,
Expand All @@ -33,6 +34,14 @@ export class ClientBase {
this._transport = transport;
}

public get timeout(): number {
return this._timeout;
}

public set timeout(timeout: number) {
this._timeout = timeout;
}

protected async _sendRequest<R extends Response>(req: FaceXRequest): Promise<R> {
dbg(req);
const encoded = await this._encoder.encode(req);
Expand All @@ -43,7 +52,7 @@ export class ClientBase {
};

dbgll('SEND:', encoded);
const text = await this._transport.post(this._url, encoded, headers);
const text = await this._transport.post(this._url, encoded, headers, this._timeout);
dbgll('RECV:', text);

let body: RawResponse;
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface FaceXRequest {
}

export interface IRemoteTransport {
post(url: URL, data: string, headers: Record<string, string>): Promise<string>;
post(url: URL, data: string, headers: Record<string, string>, timeout?: number): Promise<string>;
}

export interface IFaceXRequestEncoder {
Expand Down

0 comments on commit 7740e55

Please sign in to comment.