summaryrefslogtreecommitdiffstats
path: root/remote/test/puppeteer/packages/puppeteer-core/src/common/TaskQueue.ts
blob: 3ad1409c1b27135cbff0cdc2e1a2deea38b037f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
 * @license
 * Copyright 2020 Google Inc.
 * SPDX-License-Identifier: Apache-2.0
 */

/**
 * @internal
 */
export class TaskQueue {
  #chain: Promise<void>;

  constructor() {
    this.#chain = Promise.resolve();
  }

  postTask<T>(task: () => Promise<T>): Promise<T> {
    const result = this.#chain.then(task);
    this.#chain = result.then(
      () => {
        return undefined;
      },
      () => {
        return undefined;
      }
    );
    return result;
  }
}