diff --git a/src/nodes/WaitForAll.ts b/src/nodes/WaitForAll.ts new file mode 100644 index 0000000..a490fb9 --- /dev/null +++ b/src/nodes/WaitForAll.ts @@ -0,0 +1,41 @@ +import {ImageVar} from './io/AbstractIOSet'; +import Node from "./Node"; +import {waitForMedia} from "../utils"; + +const inputs = { + image0: { + type: 'Image' + } as ImageVar, + image1: { + type: 'Image' + } as ImageVar, +} + +const outputs = { + image0: { + type: 'Image' + } as ImageVar, + image1: { + type: 'Image' + } as ImageVar, +} + +export default class WaitForAll extends Node { + constructor(options = {}) { + super('WaitForAll', inputs, outputs); + } + + async _update() { + if (!(this.in.image0.value && this.in.image1.value)) { + return; + } + + await Promise.all([ + waitForMedia(this.in.image0.value), + waitForMedia(this.in.image1.value) + ]) + + this.out.image0.value = this.in.image0.value; + this.out.image1.value = this.in.image1.value; + } +} \ No newline at end of file diff --git a/src/nodes/index.ts b/src/nodes/index.ts index 140f07e..c40bcad 100644 --- a/src/nodes/index.ts +++ b/src/nodes/index.ts @@ -33,3 +33,4 @@ export {default as FaceFeaturePosition} from './AI/FaceFeaturePosition'; export {default as Eval} from './Eval'; export {default as QRCodeDetector} from './QRCodeDetector'; export {default as MarkerDetector} from './MarkerDetector'; +export {default as WaitForAll} from './WaitForAll';