puppeteer/packages/puppeteer-core/src/common/TaskQueue.ts

30 lines
477 B
TypeScript
Raw Normal View History

/**
2024-01-03 10:11:33 +00:00
* @license
* Copyright 2020 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
2022-06-27 07:24:23 +00:00
/**
* @internal
*/
export class TaskQueue {
2022-06-13 09:16:25 +00:00
#chain: Promise<void>;
constructor() {
2022-06-13 09:16:25 +00:00
this.#chain = Promise.resolve();
}
postTask<T>(task: () => Promise<T>): Promise<T> {
2022-06-13 09:16:25 +00:00
const result = this.#chain.then(task);
this.#chain = result.then(
() => {
return undefined;
},
() => {
return undefined;
}
);
return result;
}
}