From f0ae49019b5758389a44477914b7e13b822e791a Mon Sep 17 00:00:00 2001 From: Volpeon Date: Tue, 19 Oct 2021 16:36:56 +0200 Subject: Code improvements --- src/api/e621/index.ts | 3 ++- src/util/delay.ts | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 src/util/delay.ts (limited to 'src') diff --git a/src/api/e621/index.ts b/src/api/e621/index.ts index 32b7fc0..5c5fd2a 100644 --- a/src/api/e621/index.ts +++ b/src/api/e621/index.ts @@ -2,6 +2,7 @@ import got from "got"; import config from "../../config"; import fs from "fs/promises"; import path from "path"; +import delay from "../../util/delay"; export interface GetPostQuery { tags: readonly string[]; @@ -101,7 +102,7 @@ export async function getRandomPost(query: GetPostQuery) { const post = response.posts[postIndex]; if (dedupeDb.includes(post.id)) { - await new Promise((resolve) => setTimeout(resolve, 1000)); + await delay(1000); return getRandomPost(query); } diff --git a/src/util/delay.ts b/src/util/delay.ts new file mode 100644 index 0000000..1fc86a2 --- /dev/null +++ b/src/util/delay.ts @@ -0,0 +1 @@ +export default (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); -- cgit v1.2.3-70-g09d2