From 14821b06336caa4e77872c9d90ed6ed9b107f69a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Meier?= Date: Tue, 17 Oct 2023 15:59:39 +0200 Subject: [PATCH] Publish v0.2.11 add NonConcurrent --- package.json | 2 +- src/util/nonconcurrent.js | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/util/nonconcurrent.js diff --git a/package.json b/package.json index 4df7cc4..a6d810f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fire-lib-js", - "version": "0.2.10", + "version": "0.2.11", "author": "Sören Meier ", "type": "module", "scripts": { diff --git a/src/util/nonconcurrent.js b/src/util/nonconcurrent.js new file mode 100644 index 0000000..818fb0d --- /dev/null +++ b/src/util/nonconcurrent.js @@ -0,0 +1,27 @@ +/// synchronisation point +export default class NonConcurrent { + constructor() { + this.listeners = []; + this.running = false; + } + + // returns an object where you need to call ready once done + async start() { + if (this.running) { + await new Promise(resolve => { + this.listeners.push(resolve); + }); + } + + this.running = true; + + return { + ready: () => { + this.running = false; + const resolve = this.listeners.shift(); + if (resolve) + resolve(); + } + }; + } +} \ No newline at end of file