0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2025-01-03 05:10:13 -05:00
penpot-exporter-figma-plugin/plugin-src/Queue.ts
2024-06-19 09:38:57 +00:00

30 lines
725 B
TypeScript

import * as fastq from 'fastq';
import type { queueAsPromised } from 'fastq';
import { transformSceneNode } from '@plugin/transformers';
import { PenpotNode } from '@ui/types';
class Queue<T, R> {
private queue: queueAsPromised<T, R>;
constructor(worker: fastq.asyncWorker<unknown, T, R>, concurrency: number) {
this.queue = fastq.promise(worker, concurrency);
}
public enqueue(task: T): Promise<R> {
return this.queue.push(task);
}
public async waitIdle() {
await this.queue.drain();
}
}
export const nodeQueue = new Queue(
async ([sceneNode, position]: [SceneNode, number]): Promise<[PenpotNode | undefined, number]> => [
await transformSceneNode(sceneNode),
position
],
1
);