From 06e68eccfe6a06919dbe75396410b95d36c1eba0 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sat, 8 Jun 2024 20:59:38 +0530 Subject: [PATCH] feat: apply callback to all resolved promises --- server/src/workflow-management/storage.ts | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/server/src/workflow-management/storage.ts b/server/src/workflow-management/storage.ts index 4c78bf5a..5c7a8b06 100644 --- a/server/src/workflow-management/storage.ts +++ b/server/src/workflow-management/storage.ts @@ -60,7 +60,24 @@ export const deleteFile = (path: string): Promise => { }); }; - - - +/** + * A helper function to apply a callback to the all resolved + * promises made out of an array of the items. + * @param items An array of items. + * @param block The function to call for each item after the promise for it was resolved. + * @returns {Promise} + * @category WorkflowManagement-Storage + */ +function promiseAllP(items: any, block: any) { + let promises: any = []; + items.forEach(function(item : any, index: number) { + promises.push( function(item,i) { + return new Promise(function(resolve, reject) { + // @ts-ignore + return block.apply(this,[item,index,resolve,reject]); + }); + }(item,index)) + }); + return Promise.all(promises); +}