async function sampleTerrain(
  terrainProvider,
  level,
  positions,
  rejectOnTileFail,
) {
  if (!defined(rejectOnTileFail)) {
    rejectOnTileFail = false;
  }
  //>>includeStart('debug', pragmas.debug);
  Check.typeOf.object("terrainProvider", terrainProvider);
  Check.typeOf.number("level", level);
  Check.typeOf.bool("rejectOnTileFail", rejectOnTileFail);
  Check.defined("positions", positions);
  //>>includeEnd('debug');

  return doSampling(terrainProvider, level, positions, rejectOnTileFail);
}
Initiates a terrain height query for an array of {@link Cartographic} positions by
requesting tiles from a terrain provider, sampling, and interpolating.  The interpolation
matches the triangles used to render the terrain at the specified level.  The query
happens asynchronously, so this function returns a promise that is resolved when
the query completes.  Each point height is modified in place.  If a height can not be
determined because no terrain data is available for the specified level at that location,
or another error occurs, the height is set to undefined.  As is typical of the
{@link Cartographic} type, the supplied height is a height above the reference ellipsoid
(such as {@link Ellipsoid.WGS84}) rather than an altitude above mean sea level.  In other
words, it will not necessarily be 0.0 if sampled in the ocean. This function needs the
terrain level of detail as input, if you need to get the altitude of the terrain as precisely
as possible (i.e. with maximum level of detail) use {@link sampleTerrainMostDetailed}.

@function sampleTerrain

@param {TerrainProvider} terrainProvider The terrain provider from which to query heights.
@param {number} level The terrain level-of-detail from which to query terrain heights.
@param {Cartographic[]} positions The positions to update with terrain heights.
@param {boolean} [rejectOnTileFail=false] If true, for any failed terrain tile requests, the promise will be rejected. If false, returned heights will be undefined.
@returns {Promise<Cartographic[]>} A promise that resolves to the provided list of positions when terrain the query has completed.

@see sampleTerrainMostDetailed

@example
// Query the terrain height of two Cartographic positions
const terrainProvider = await Cesium.createWorldTerrainAsync();
const positions = [
    Cesium.Cartographic.fromDegrees(86.925145, 27.988257),
    Cesium.Cartographic.fromDegrees(87.0, 28.0)
];
const updatedPositions = await Cesium.sampleTerrain(terrainProvider, 11, positions);
// positions[0].height and positions[1].height have been updated.
// updatedPositions is just a reference to positions.

// To handle tile errors, pass true for the rejectOnTileFail parameter.
try {
   const updatedPositions = await Cesium.sampleTerrain(terrainProvider, 11, positions, true);
} catch (error) {
  // A tile request error occurred.
}