Skip to content

Commit

Permalink
Add way to abort search requests (#2877)
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy authored Nov 14, 2022
1 parent b454318 commit 0e32284
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/@types/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,6 @@ export interface ISearchResults {
count?: number;
next_batch?: string;
pendingRequest?: Promise<ISearchResults>;
abortSignal?: AbortSignal;
}
/* eslint-enable camelcase */
6 changes: 4 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6389,7 +6389,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
next_batch: searchResults.next_batch,
};

const promise = this.search(searchOpts)
const promise = this.search(searchOpts, searchResults.abortSignal)
.then(res => this.processRoomEventsSearch(searchResults, res))
.finally(() => {
searchResults.pendingRequest = undefined;
Expand Down Expand Up @@ -8439,17 +8439,19 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @param {Object} opts
* @param {string} opts.next_batch the batch token to pass in the query string
* @param {Object} opts.body the JSON object to pass to the request body.
* @param {AbortSignal=} abortSignal optional signal used to cancel the http request.
* @return {Promise} Resolves: TODO
* @return {module:http-api.MatrixError} Rejects: with an error response.
*/
public search(
opts: { body: ISearchRequestBody, next_batch?: string }, // eslint-disable-line camelcase
abortSignal?: AbortSignal,
): Promise<ISearchResponse> {
const queryParams: any = {};
if (opts.next_batch) {
queryParams.next_batch = opts.next_batch;
}
return this.http.authedRequest(Method.Post, "/search", queryParams, opts.body);
return this.http.authedRequest(Method.Post, "/search", queryParams, opts.body, { abortSignal });
}

/**
Expand Down

0 comments on commit 0e32284

Please sign in to comment.