import { deleteImage } from "../deno-gyazo/mod.ts";
import { pool, sort, Result } from "../async-lib/mod.ts";
//import { deleteImage } from "../deno-gyazo/mod.ts";


export async function* deleteBulk(
  imageIds: string[],
  accessToken: string,
): AsyncGenerator<Result<string>, void, unknown> {
  // access token取得
  if (!accessToken) throw new Error("Could not get the access token");
  
  const reader = pool(
    5,
    Array(imageIds.length).keys(),
    async (index: number): Promise<string> => {
      const result = await deleteImage(imageIds[index], {
        accessToken,
      });
      if (!result.ok) throw new Error(JSON.stringify(result.value));
      return imageIds[index];
    },
  );
  
  yield* sort([...reader]);
};