export type Future<T = void> = PromiseWithResolvers<T>;
export class FutureMap<T = void> extends Map<number, Future<T>> {
  add(tileId: number) {
    const future = Promise.withResolvers<T>();
    this.set(tileId, future);
    return future.promise;
  }

  resolve(tileId: number, value: T) {
    this.get(tileId)?.resolve(value);
    this.delete(tileId);
  }

  reject(tileId: number, reason: unknown) {
    this.get(tileId)?.reject(reason);
    this.delete(tileId);
  }
}
