chore: type updates

This commit is contained in:
鲁树人 2023-05-15 00:09:38 +01:00
parent cf3324e833
commit 3c0a9433dd
2 changed files with 5 additions and 3 deletions

View File

@ -27,7 +27,7 @@ export abstract class ConcurrentQueue<T> {
} }
private async processQueue() { private async processQueue() {
while (true) { while (this.items.length > 0) {
const item = this.items.pop(); const item = this.items.pop();
if (item === undefined) { if (item === undefined) {
break; break;

View File

@ -1,6 +1,8 @@
import { nanoid } from 'nanoid'; import { nanoid } from 'nanoid';
export class WorkerClientBus { /* eslint-disable @typescript-eslint/no-explicit-any */
export class WorkerClientBus<T = string> {
private idPromiseMap = new Map<string, [(data: any) => void, (error: Error) => void]>(); private idPromiseMap = new Map<string, [(data: any) => void, (error: Error) => void]>();
constructor(private worker: Worker) { constructor(private worker: Worker) {
@ -22,7 +24,7 @@ export class WorkerClientBus {
}); });
} }
async request<R = any, P = any>(actionName: string, payload: P): Promise<R> { async request<R = any, P = any>(actionName: T, payload: P): Promise<R> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const id = nanoid(); const id = nanoid();
this.idPromiseMap.set(id, [resolve, reject]); this.idPromiseMap.set(id, [resolve, reject]);