message: cli: update worker queue to allow async factory function
diff: @@ -135,7 +135,11 @@ export type WorkerQueueThreadsOptions<TItem, TResult, TData> = {
  * note that they are both copied by value into the worker thread, except for
  * types that are explicitly shareable across threads, such as `SharedArrayBuffer`.
  */
  - workerFactory: (data: TData) => (item: TItem) => Promise<TResult>;
  + workerFactory: (
  + data: TData,
  + ) =>
  + | ((item: TItem) => Promise<TResult>)
  + | Promise<(item: TItem) => Promise<TResult>>;
  /** Data supplied to each worker factory */
  workerData?: TData;
  /** Number of threads, defaults to half of the number of available CPUs */
  @@ -209,11 +213,16 @@ export async function runWorkerQueueThreads<TItem, TResult, TData>(
  }
  function workerQueueThread(
  - workerFuncFactory: (data: unknown) => (item: unknown) => Promise<unknown>,
  + workerFuncFactory: (
  + data: unknown,
  + ) => Promise<(item: unknown) => Promise<unknown>>,
  ) {
  const { parentPort, workerData } = require('worker_threads');
  - const workerFunc = workerFuncFactory(workerData);
  + Promise.resolve()
  + .then(() => workerFuncFactory(workerData))
  + .then(
  + workerFunc => {
  parentPort.on('message', async (message: WorkerThreadMessage) => {
  if (message.type === 'done') {
  parentPort.close();
  @@ -234,6 +243,9 @@ function workerQueueThread(
  });
  parentPort.postMessage({ type: 'start' });
  + },
  + error => parentPort.postMessage({ type: 'error', error }),
  + );
  }
  export type WorkerThreadsOptions<TResult, TData, TMessage> = {
  