From cf6f2ac5075a329c496fe619c7a234939ceef957 Mon Sep 17 00:00:00 2001 From: George Svarovsky Date: Sun, 27 Dec 2020 10:20:00 +0000 Subject: [PATCH] AsyncIterator _end race condition workaround --- lib/get/leveliterator.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/get/leveliterator.ts b/lib/get/leveliterator.ts index 0a19c16..c71ec82 100644 --- a/lib/get/leveliterator.ts +++ b/lib/get/leveliterator.ts @@ -56,13 +56,15 @@ export class LevelIterator extends BufferedIterator { protected _end(destroy?: boolean) { - super._end(destroy); - if (!destroy) { - this.level.end((endErr?: Error) => { - if (endErr) { - this.emit('error', endErr); - } - }); + if (!this.ended) { + super._end(destroy); + if (!destroy) { + this.level.end((endErr?: Error) => { + if (endErr) { + this.emit('error', endErr); + } + }); + } } }