Skip to content

Commit

Permalink
Renamed and documented experimental fetchData function.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Jul 31, 2020
1 parent c414a45 commit 2c49a52
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/web/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ export type FetchJsonResponse = {

type Header = { key: string, value: string };

export function fetchData<T = Uint8Array>(connection: string | ConnectionInfo, body?: Uint8Array, processFunc?: (value: Uint8Array, response: FetchJsonResponse) => T): Promise<T> {
// This API is still a work in progress; the future changes will likely be:
// - ConnectionInfo => FetchDataRequest<T = any>
// - FetchDataRequest.body? = string | Uint8Array | { contentType: string, data: string | Uint8Array }
// - If string => text/plain, Uint8Array => application/octet-stream (if content-type unspecified)
// - FetchDataRequest.processFunc = (body: Uint8Array, response: FetchDataResponse) => T
// For this reason, it should be considered internal until the API is finalized
export function _fetchData<T = Uint8Array>(connection: string | ConnectionInfo, body?: Uint8Array, processFunc?: (value: Uint8Array, response: FetchJsonResponse) => T): Promise<T> {

// How many times to retry in the event of a throttle
const attemptLimit = (typeof(connection) === "object" && connection.throttleLimit != null) ? connection.throttleLimit: 12;
Expand Down Expand Up @@ -320,7 +326,7 @@ export function fetchJson(connection: string | ConnectionInfo, json?: string, pr
connection = updated;
}

return fetchData<any>(connection, body, processJsonFunc);
return _fetchData<any>(connection, body, processJsonFunc);
}

export function poll<T>(func: () => Promise<T>, options?: PollOptions): Promise<T> {
Expand Down

0 comments on commit 2c49a52

Please sign in to comment.