tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

TaskQueue.ts (478B)


      1 /**
      2 * @license
      3 * Copyright 2020 Google Inc.
      4 * SPDX-License-Identifier: Apache-2.0
      5 */
      6 
      7 /**
      8 * @internal
      9 */
     10 export class TaskQueue {
     11  #chain: Promise<void>;
     12 
     13  constructor() {
     14    this.#chain = Promise.resolve();
     15  }
     16 
     17  postTask<T>(task: () => Promise<T>): Promise<T> {
     18    const result = this.#chain.then(task);
     19    this.#chain = result.then(
     20      () => {
     21        return undefined;
     22      },
     23      () => {
     24        return undefined;
     25      },
     26    );
     27    return result;
     28  }
     29 }