當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


JavaScript ArcGIS promiseUtils.createAbortError用法及代碼示例


基本信息

以下是所在類或對象的基本信息。

AMD: require(["esri/core/promiseUtils"], (promiseUtils) => { /* code goes here */ });

ESM: import * as promiseUtils from "@arcgis/core/core/promiseUtils";

對象: esri/core/promiseUtils

自從:用於 JavaScript 4.2 的 ArcGIS API

用法說明

promiseUtils.createAbortError函數(或屬性)的定義如下:

createAbortError () {Error}


創建一個特殊的錯誤對象,用於在承諾鏈中發出中止請求的信號。由於abort signals 而被拒絕的 Promise 應該以這種錯誤被拒絕。

返回:

類型 說明
Error 一個特殊的錯誤對象,表示一個中止的請求。

例子:

// Request multiple files and return results in an array
function requestMultiple(urls, abortSignal) {
  // Fire off requests
  let promises = urls.map(url => request(url, { signal: abortSignal });

  // Wait until all requests have either resolved or rejected
  promiseUtils.eachAlways(urls)
    .then(results => {
      if (abortSignal && abortSignal.aborted) {
        // If the user has triggered the abortSignal, all requests will react and reject. eachAlways resolves with
        // an array that contains the reject error for each request. Instead of returning this array as a result, we
        // should reject the promise returned to the user with an abort error.
        throw promiseUtils.createAbortError();
      }
      return results;
  });
}

相關用法


注:本文由純淨天空篩選整理自arcgis.com大神的英文原創作品 promiseUtils.createAbortError。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。