From 8d90d58143327aa8a4c98623ac22be26a8aa719f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 28 Sep 2020 14:55:40 +0200 Subject: [PATCH] Make output more deterministic (#13) Depending on the speed of the getRows() call the keys within the resulting object might be ordered differently in between runs. Synchronously set the values tp ensure a deterministic result. --- src/manager.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/manager.ts b/src/manager.ts index fe2c798..533c7e4 100644 --- a/src/manager.ts +++ b/src/manager.ts @@ -184,17 +184,24 @@ export class Manager { meta, }; - await Promise.all( + const entries = await Promise.all( blacklists.map( - async (blacklist: Blacklist): Promise => { - data[blacklist.type] = await blacklist.getRows( - new Date(start).getTime(), - new Date(end).getTime(), - ); + async (blacklist: Blacklist): Promise => { + return { + blacklist, + rows: blacklist.getRows( + new Date(start).getTime(), + new Date(end).getTime(), + ) + }; }, ), ); + entries.forEach(entry => { + data[entry.blacklist.type] = entry.rows + }); + const directory = path.dirname(filename); if (!(await fsExists(directory))) { await fsMkdir(directory); -- 2.20.1