Skip to content

Commit

Permalink
Add abortSignal to query execution
Browse files Browse the repository at this point in the history
  • Loading branch information
j3lte committed Dec 6, 2023
1 parent 77bfe45 commit bf44a22
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,26 +374,30 @@ export class SodaQuery<T> {

execute(
queryID?: string,
signal?: AbortSignal,
): DataResponse<Array<T & ExtraDataFields>> {
return this.requestData<Array<T & ExtraDataFields>>(this.getURL(queryID)).then((res) => ({
return this.requestData<Array<T & ExtraDataFields>>(this.getURL(queryID), { signal }).then((
res,
) => ({
...res,
data: res.data ?? [],
}));
}

executeGeoJSON(
queryID?: string,
signal?: AbortSignal,
): DataResponse<unknown> {
const url = this.getURL(queryID).replace(/\.json/, ".geojson");
return this.requestData<unknown>(url).then((res) => ({
return this.requestData<unknown>(url, { signal }).then((res) => ({
...res,
data: res.data ?? { type: "FeatureCollection", features: [] },
}));
}

getMetaData(): DataResponse<unknown> {
getMetaData(signal?: AbortSignal): DataResponse<unknown> {
const url = `https://${this.#domain}/api/views/${this.#datasetId}`;
return this.requestData(url);
return this.requestData(url, { signal });
}
}

Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface Options {

export interface RequesOpts {
method?: string;
signal?: AbortSignal;
}

export interface ExtraDataFields {
Expand Down

0 comments on commit bf44a22

Please sign in to comment.