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