<NME> raw.ts
<BEF> /**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import {postProcessRawData} from 'neuroglancer/sliceview/backend_chunk_decoders/postprocess';
import {VolumeChunk} from 'neuroglancer/sliceview/volume/backend';
import {DATA_TYPE_BYTES, DataType} from 'neuroglancer/util/data_type';
import {convertEndian16, convertEndian32, Endianness, ENDIANNESS} from 'neuroglancer/util/endian';
import {prod3} from 'neuroglancer/util/geom';

export function decodeRawChunk(
    chunk: VolumeChunk, response: ArrayBuffer, endianness: Endianness = ENDIANNESS,
    byteOffset: number = 0, byteLength: number = response.byteLength) {
  let {spec} = chunk.source!;
  let {dataType} = spec;
  let numElements = prod3(chunk.chunkDataSize!);
  let bytesPerElement = DATA_TYPE_BYTES[dataType];
  let expectedBytes = numElements * bytesPerElement;
  if (expectedBytes !== byteLength) {
    throw new Error(
        `Raw-format chunk is ${byteLength} bytes, ` +
        `but ${numElements} * ${bytesPerElement} = ${expectedBytes} bytes are expected.`);
  }
  const data = makeDataTypeArrayView(dataType, response, byteOffset, byteLength);
  convertEndian(data, endianness, bytesPerElement);
  await postProcessRawData(chunk, cancellationToken, data);
}
    default:
      throw new Error(`Unexpected data type: ${dataType}.`);
  }
  postProcessRawData(chunk, data);
}

<MSG> feat: add async_computation workers for decoding chunk data

Decoding of volumetric chunk data is now done in separate "async_computation" worker threads.
Decoding of VTK meshes and CSV vertex attributes is also done in the "async_computation" worker
threads.  Decoding of segmentation mesh data is not yet done in the "async_computation" worker
threads, though.

<DFF> @@ -16,13 +16,16 @@
 
 import {postProcessRawData} from 'neuroglancer/sliceview/backend_chunk_decoders/postprocess';
 import {VolumeChunk} from 'neuroglancer/sliceview/volume/backend';
+import {CancellationToken} from 'neuroglancer/util/cancellation';
 import {DATA_TYPE_BYTES, DataType} from 'neuroglancer/util/data_type';
 import {convertEndian16, convertEndian32, Endianness, ENDIANNESS} from 'neuroglancer/util/endian';
 import {prod3} from 'neuroglancer/util/geom';
 
-export function decodeRawChunk(
-    chunk: VolumeChunk, response: ArrayBuffer, endianness: Endianness = ENDIANNESS,
-    byteOffset: number = 0, byteLength: number = response.byteLength) {
+export async function decodeRawChunk(
+    chunk: VolumeChunk, cancellationToken: CancellationToken, response: ArrayBuffer,
+    endianness: Endianness = ENDIANNESS, byteOffset: number = 0,
+    byteLength: number = response.byteLength) {
+  cancellationToken;
   let {spec} = chunk.source!;
   let {dataType} = spec;
   let numElements = prod3(chunk.chunkDataSize!);
@@ -54,5 +57,5 @@ export function decodeRawChunk(
     default:
       throw new Error(`Unexpected data type: ${dataType}.`);
   }
-  postProcessRawData(chunk, data);
+  await postProcessRawData(chunk, cancellationToken, data);
 }

feat: add async_computation workers for decoding chunk data