Programmatic request cancellation of CzmlDataSource.process()


I have a case where I need to programmatically cancel a Resource based request fetching CZML data. The request may be long-running, and the user may leave the page or sign out during the request’s pending state.
The resource is created like so:

const czmlResource = () => new Resource({
    url: ''

… and it is used like so:

await czmlDataSource.process(czmlResource);

I cannot find anything in the documentation regarding cancellation of the API call created by the .process() method. Is that correct, or is there a way to programmatically cancel it?

Request objects do have a cancel function, but its private-- meaning it won’t show up in our API documentation and is subject to break in a new release without warning.

The request is always defined on the Resource object. So you could do something like the following, but it may have other implications…

const request = czmlResource.request;
if (
    request.state === RequestState.ISSUED ||
    request.state === RequestState.ACTIVE
  ) {

Thanks, Gabby.
As long as the solution relies on using a private API, I’ll have to solve it differently.
For future reference: I think my current solution will be to avoid using the new Resource({}) way of retrieving data, and instead rely on fetch() and process the JSON results with CzmlDataSource.process(). That way I’ll be able to hook on to fetch()'s AbortController for request cancellation.

I see. Currently I don’t think cancelling is supported in the public API.

We have been considering refactoring Resource to work with native fetch, which I think would help use cases like this. But no work is scheduled around this yet.

1 Like