Skip to content

Commit 0e32284

Browse files
authored
Add way to abort search requests (#2877)
1 parent b454318 commit 0e32284

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/@types/search.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,6 @@ export interface ISearchResults {
114114
count?: number;
115115
next_batch?: string;
116116
pendingRequest?: Promise<ISearchResults>;
117+
abortSignal?: AbortSignal;
117118
}
118119
/* eslint-enable camelcase */

src/client.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6389,7 +6389,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
63896389
next_batch: searchResults.next_batch,
63906390
};
63916391

6392-
const promise = this.search(searchOpts)
6392+
const promise = this.search(searchOpts, searchResults.abortSignal)
63936393
.then(res => this.processRoomEventsSearch(searchResults, res))
63946394
.finally(() => {
63956395
searchResults.pendingRequest = undefined;
@@ -8439,17 +8439,19 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
84398439
* @param {Object} opts
84408440
* @param {string} opts.next_batch the batch token to pass in the query string
84418441
* @param {Object} opts.body the JSON object to pass to the request body.
8442+
* @param {AbortSignal=} abortSignal optional signal used to cancel the http request.
84428443
* @return {Promise} Resolves: TODO
84438444
* @return {module:http-api.MatrixError} Rejects: with an error response.
84448445
*/
84458446
public search(
84468447
opts: { body: ISearchRequestBody, next_batch?: string }, // eslint-disable-line camelcase
8448+
abortSignal?: AbortSignal,
84478449
): Promise<ISearchResponse> {
84488450
const queryParams: any = {};
84498451
if (opts.next_batch) {
84508452
queryParams.next_batch = opts.next_batch;
84518453
}
8452-
return this.http.authedRequest(Method.Post, "/search", queryParams, opts.body);
8454+
return this.http.authedRequest(Method.Post, "/search", queryParams, opts.body, { abortSignal });
84538455
}
84548456

84558457
/**

0 commit comments

Comments
 (0)