cancel(promise)
Cancels a request using the provided request promise.
Declaration
cancel(promise: Promise<unknown>): boolean;Parameters
- promise:
Pass the promise returned from the service method. Passing an invalid promise or the promise of a completed request has no effect.
Mentioned in
Return Value
true if the server cancels the pending search request.
Discussion
Sometimes you need to cancel a request, either because a person initiates the cancellation or moves on to another activity.
The preferred way to cancel a request is to use an AbortSignal. Pass the signal property of an AbortController to the service method’s options, and call abort() on the controller when you need to cancel the request.
Alternatively, you can cancel a request by passing its returned promise to the cancel(promise) method:
const search = new mapkit.Search();
const promise = search.search("coffee");
// Cancel the request:
search.cancel(promise);