Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add way to abort search requests #2877

Merged
merged 1 commit into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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